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

x
  • 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)
0
mte01
Asked:
mte01
  • 3
  • 2
1 Solution
 
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
 
mte01Author Commented:
Apparently the UltraGrid in Infragistics doesn't have a TableStyles property, so your last statement won't work....
0
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!

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

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