auxcom Posted April 29, 2007 Posted April 29, 2007 Hi! I have a class inherited from CollectionBase. It binds perfectly to a control (DataGrid or GridView). What I want is to change the order of the CollectionBase members so that it will appear as I want it to the DataGrid as columns? Here is some code. Public Class Contact Private Name As String Private Fax As String End Class Public Class ContactCollection Inherits CollectionBase Default Public Property Item(ByVal index As Integer) As Contact Get Return CType(List(index), Contact) End Get Set(ByVal value As Contact) List(index) = value End Set End Property End Class When I do: DataGrid.Datasource = ContactCollection A column name "Fax" appear first and the "Name" as second column of the Datagrid. I want to make Name to be the first column and Fax as the second column. I hope there is a solution by adding some code in the Contact and ContactCollection class not by re-ordering the columns of the Datagrid. Thanks! I appreciate any help. Quote
shaul_ahuva Posted April 30, 2007 Posted April 30, 2007 The easiest (and probably most correct) way to handle this would be to extend the DataGrid class and override the CreateColumnSet method. In your overridden method, order the ArrayList of DataGridColumn instances as desired. Quote
auxcom Posted April 30, 2007 Author Posted April 30, 2007 Thanks for reply. I will think about that solution Here is the other solution I found. http://www.timvw.be/control-the-order-of-properties-in-your-class/ I just haven't make it work :) Quote
shaul_ahuva Posted May 1, 2007 Posted May 1, 2007 It looks like that will work as well, though there are major problems I see from a design standpoint (display information is contained in the type definition and, more importantly, the solution relies on the internal behavior of the DataGrid). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.