This is a migrated thread and some comments may be shown as answers.

How To: Determine order of columns in grid associated with datatable

0 Answers 76 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jorge Gonzalez
Top achievements
Rank 1
Jorge Gonzalez asked on 11 Jan 2010, 10:52 PM
Hello,
     When a column on the grid is re-ordered there appears to be only the DisplayIndexMap object in the grid to keep track of the new order. This object is protected so I cannot get at it directly. Since I could not figure out how to determine the new order on the grid side I changed the column order of the datatable to match the grid's.

In the ColumnDisplayIndexChanged event of the grid I added this line of code, which takes care of the re-ordering:

<datatable name>.Columns[e.Column.Header.ToString()].SetOrdinal(e.Column.DisplayIndex);

This event will be triggered twice. Once for the column that was moved and again for the column that was shifted over for the moved column.

When I print the contents of the grid I use the datatable as the data source.


No answers yet. Maybe you can help?

Tags
GridView
Asked by
Jorge Gonzalez
Top achievements
Rank 1
Share this question
or