order CollectionBase members

auxcom

Freshman
Joined
Apr 1, 2004
Messages
49
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.
 
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.
 
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).
 
Back
Top