Add Column in DataTable at a specified position

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I would like to insert a new column in DataTable at a specified position
Unfortunatly, the DataColumnCollection does not expose any method to do this (like AddAt)

In fact, the AddAt method exists for the class DataColumnCollection, but is "private"

Thanks.
 
In fact, I need to transform some columns the DataTable after the Select (changing the DataType, Transform Code in user readable label, Business data transformation...
So my code create a new Column, parse the Rows to calculate the values in this new Column, and delete the old Column. And I would like this new Column is at the same place of the old Colum

Unfortunatly, I am in a generic process where the user chooses columns to retrieve, the program selects this Column from DB to the DataTable, and show the results in a DataGrid where BoundColumns is programmatically added in the same order of the DataTable

In fact, I have found a alternative but it is not very nice : I use the ExtendedProperty of DataColumn to put a self-made index for display ( ExtendedProperty["DisplayIndex"] = i ). This self-made index is used to display the results

Thanks.
 
Hi,

I see.
Why don't you just replace the old values instead of creating new column?

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

lstefair said:
In fact, I need to transform some columns the DataTable after the Select
(changing the DataType, Transform Code in user readable label, Business data
transformation...)
So my code create a new Column, parse the Rows to calculate the values in
this new Column, and delete the old Column. And I would like this new Column
is at the same place of the old Column
Unfortunatly, I am in a generic process where the user chooses columns to
retrieve, the program selects this Column from DB to the DataTable, and show
the results in a DataGrid where BoundColumns is programmatically added in
the same order of the DataTable.
In fact, I have found a alternative but it is not very nice : I use the
ExtendedProperty of DataColumn to put a self-made index for display (
ExtendedProperty["DisplayIndex"] = i ). This self-made index is used to
display the results.
 
Back
Top