Order of Columns in DataGrid

Hey experts,

I am using an Infragistics UltraGrid (but this question can be generalized to any datagrid), and I want to change the position of columns 14,15,16 to positions 10,11,12, but since the datagrid is bound to a dataset, it doesn't seem that I can do that, so I reformed the SQL statement to output the columns in the order that I want them, but again they would appear at runtime in their order in the database!!....any help on re-ordering the columns ??(it doesn't matter if it's via th datagrid itself or after doing a select statement)
LVL 3
mte01Asked:
Who is Participating?
 
CetusMODCommented:
PAQ'd, 150 points refunded.
CetusMOD
Community Support Moderator
0
 
jatinderalaghCommented:
You can use TableStyles property of datagrid to map the columns of datagrid to the datacolumn of datatable.

private void AddDataGridTableStyle()
{
   // Create a new DataGridTableStyle and set MappingName.
   DataGridTableStyle myGridStyle =
   new DataGridTableStyle();
// set the table stylke to datatable
   myGridStyle.MappingName = "Customers";

   // Create two DataGridColumnStyle objects.
   DataGridColumnStyle colStyle1 =
   new DataGridTextBoxColumn();
// Map the first column to first name column in datatable
   colStyle1.MappingName = "firstName";
   
// Map the first column to Current column in datatable
   DataGridColumnStyle colStyle2 =
   new DataGridBoolColumn();
   colStyle2.MappingName = "Current";

   // Add column styles to table style.
   myGridStyle.GridColumnStyles.Add(colStyle1);
   myGridStyle.GridColumnStyles.Add(colStyle2);  

   // Add the grid style to the GridStylesCollection.
   myDataGrid.TableStyles.Add(myGridStyle);
}


http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21247295.html

Jatinder
0
 
mte01Author Commented:
OK...I will try this, bu the select statement should work if I did it....shouldn't it??
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
mte01Author Commented:
Apparently the UltraGrid in Infragistics doesn't have a TableStyles property, so your last statement won't work....
0
 
jatinderalaghCommented:
OK...I will try this, bu the select statement should work if I did it....shouldn't it??

>> This should work also as the order of columns in datatable object depends on your sql query.
0
 
mte01Author Commented:
I found a solution to my problem, by setting the dataset of the datagrid of null, and then binding the datagrid to this null dataset, and then continuing normally by resetting the datagrid's dataset to the result of the new SQL statement, and everything appeared as I wanted....I will request to delete this question if there aren't any objections....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.