Question Data Sources members order

nicorvp

Member
Joined
May 3, 2009
Messages
24
Location
Italy
Programming Experience
5-10
How to order data source members so that you haven't to reorder datagridview columns each time you generate the binded class?
Thanks
 
If I'm understanding your question correctly, you want to place an Order By into your query statement that is filling your datasource attached to your datagridview control.
 
No, sorry, I was meaning If I want to bind a class on a datagrid view I drag the class data source built from the class on the datagridview.
If I add a property to the class and I want to show it as column in the datagridview, I have to rebuilt the class and redrag the data source on the datagridview.
My problem is that columns on the datagrid view dispose themselves in an apparently random order. How to prevent this "random order" and to impose the column order?
Thanks
 
Select "Edit columns..." (context menu or DGV tasks menu), select a column and click the up/down arrows to reorder.
 
Yes, but this way each time you add or remove a property from the binded class and you want to show the new column in the datagridview, you have to reorder manually each columns.
Isn't there a way to set the column order programmatically ?
 
There's isn't in the object datasource itself (the class definition), but you can set the DisplayIndex property of each column.
 
You could just use a DataTable; whatever you have as the name and type of your properties can certainly be set as the name/type of a column, and the IDE knows to get the columns out in order
 
Thanks for the reply.
Cjard, can you explain something more about how to set the Datatable? Do you mean to tranform my class in a datatable to be binded to the datagridview?
 
Back
Top