Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

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)
  • 3
  • 2
1 Solution
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.

   // Add the grid style to the GridStylesCollection.


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

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
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....
PAQ'd, 150 points refunded.
Community Support Moderator

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now