Order of Columns in the Datagrid binding.

  • Thread starter Thread starter John Sun
  • Start date Start date
J

John Sun

Hi, Dear gurus,

I want to bind my collection to a datagrid. The field names in my object
show up in a weird order, and I just wonder how I could reorder those
columns .

I find some code like the following , but I don't want to do it that way
because it won't work if I have large number of fields.
[
DataGridTableStyle myGridStyle = new DataGridTableStyle();

myGridStyle.MappingName = "GridTableMappingName";



DataGridTextBoxColumn nameColumnStyle = new DataGridTextBoxColumn();

nameColumnStyle.MappingName = "GridColumnMappingName";

nameColumnStyle.HeaderText= "GridColumnMappingName";

myGridStyle.GridColumnStyles.Add(nameColumnStyle);

myDataGrid.TableStyles.Add(myGridStyle);

]

I believe there must be some better way to do that(using reflection) .
Anybody gives me some hint on that. A link to a example is highly
appreciated.




Thanks,
J.W.
 
Hi,

Use collection as the mapping name for the tablestyle if you are
binding to a collection. Arraylist if you are binding to an arraylist.

Ken
----------------
Hi, Dear gurus,

I want to bind my collection to a datagrid. The field names in my object
show up in a weird order, and I just wonder how I could reorder those
columns .

I find some code like the following , but I don't want to do it that way
because it won't work if I have large number of fields.
[
DataGridTableStyle myGridStyle = new DataGridTableStyle();

myGridStyle.MappingName = "GridTableMappingName";



DataGridTextBoxColumn nameColumnStyle = new DataGridTextBoxColumn();

nameColumnStyle.MappingName = "GridColumnMappingName";

nameColumnStyle.HeaderText= "GridColumnMappingName";

myGridStyle.GridColumnStyles.Add(nameColumnStyle);

myDataGrid.TableStyles.Add(myGridStyle);

]

I believe there must be some better way to do that(using reflection) .
Anybody gives me some hint on that. A link to a example is highly
appreciated.




Thanks,
J.W.
 
Hi, Ken,

That's what I am using now. It have to manually add each field in my class
to "GridColumnStyles" collection in order to arrange the column display
order.

What I am looking for is some better way to handle that, like, I can apply
some attributes to my class, so the datagrid knows how to display my fields
names in a particular order.

Thanks !

J.W.
 
Back
Top