Defining windows datagrid columns at run time.

Defining windows datagrid columns at run time.

Old forum URL: forums.lhotka.net/forums/t/7124.aspx


gwilliams posted on Wednesday, June 17, 2009

 

 

How would you bind a childlist to a windows datagrid and only display the columns of the child that you want? Without creating a datasource that is bound to the object.

rsbaker0 replied on Thursday, June 18, 2009

I have done this with a DevExpress grid but I assume the process would work with any grid that had an interface for specifically setting the columns to show.

Basically, we use reflection to traverse the property list for the type of object to be displayed. You can get the property list from the .NET Type without having created the data to be bound.

Then you add columns for each property that you want to display. In our case, we tag each such property with an attribute that has the caption for the column and desired display order. This tells us which columns to add and in what order.

You may also want to have a provision for allowing the user to change the column order or sizes and remember this for the next time.

Copyright (c) Marimer LLC