Order of Columns in DataGrid

Posted on 2005-05-01
Last Modified: 2012-08-14
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)
Question by:mte01
    LVL 11

    Expert Comment

    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.

    LVL 3

    Author Comment

    OK...I will try this, bu the select statement should work if I did it....shouldn't it??
    LVL 3

    Author Comment

    Apparently the UltraGrid in Infragistics doesn't have a TableStyles property, so your last statement won't work....
    LVL 11

    Expert Comment

    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.
    LVL 3

    Author Comment

    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....

    Accepted Solution

    PAQ'd, 150 points refunded.
    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now