Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Datagrid and custom collection as datasource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen Ritchie - 21 Feb 2006 15:11 GMT
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
 .
 .
 End Property

 Public Property Type As OrderNumberType
 .
 .
 End Property

End Class

Public Class OrderNumberType

 Public Property ID as Integer
 .
 .
 End Property

 Public Property Description As String
 .
 .
 End Property

End Class

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 !
Markus - 21 Feb 2006 15:41 GMT
> 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
[quoted text clipped - 9 lines]
>
> 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
Stephen Ritchie - 21 Feb 2006 16:00 GMT
Markus

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

> > 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
[quoted text clipped - 27 lines]
>
> Markus
Markus - 21 Feb 2006 19:02 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.