Datagrid and custom collection as datasource

G

Guest

All,

I have successfully used custom collections as the datasource for a datagrid
previously however this one is causing me problems as one of the properties
of the objects within the collection relate to another custom object as
follows

Public Class OrderNumber

Public property Number As String
 
M

Markus

I have successfully used custom collections as the datasource for a datagrid
previously however this one is causing me problems as one of the properties
of the objects within the collection relate to another custom object as
follows
I have a collection that inherits CollectionBase called
OrderNumberCollection that I can add individual OrderNumber objects to and
everything is OK.

However when I then set

datagrid.datasource = OrderNumberCollection

I can see all the properties of object OrderNumber as columns, however
within the grid rows the value of the OrderType column is
"<namespace>.OrderType" and what I want is for it to be OrderType.Description

Any thoughts welcomed !

If your on Framework 2.0 I'd suggest to switch to a datagridview and
handle the Format event:

Event: datagridview.Format

in the EventHandler you can set the Value in the from the EventArgs (e):
e.Value = ((OrderType)e.Value).Description

(sorry, my notation is c# as I don't know VB well, hope to give you some
input anyways).

Markus
 
M

Markus

Thanks for the reply, however I am not on NET 2.0. Any other
possibilities ?

Very sad, as the 2.0 version brings a lot of new features to the
DataGrid and the new DataGridView.

However, what you can try is to define custom Columns in the grid, e.g.
suitable for you might be the DataGridTextBoxColumn. It provides a
Property "Format" and "FormatInfo" where you can set any custom
IFormatProvider and a Format String.

Additionally the DataGridTextBoxColumn has the Methods
"SetColumnValueAtRow" and "GetColumnValueAtRow", maybe they are useful...

however, I have not tested anything of the above, but good luck and
sorry, I can't provide more informations.

Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top