Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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.
Posted
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).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...