PC Review


Reply
Thread Tools Rate Thread

Binding Custom Collection/Objects

 
 
Merk
Guest
Posts: n/a
 
      9th Sep 2006
I'm new to .NET (using 2.0) and was wondering how to go about binding a
collection of custom classes to a DataGrid.

The class exposes 5 read-only String properties. I would like for each of
these properties to appear in a column in the DataGrid.

The end result would be that when the collection has 35 objects in it, the
DataGrid would have 35 rows and 5 columns (after being bound to the
collection).

Specifically -
1. which collection class could/should I use (or do I need to roll my own to
make it "bindable")?
and/or
2. how do I make my objects in that collection "bindable" to the DataGrid?

Thanks.


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      9th Sep 2006
Merk,

I would take a look into the BindingList<T> class in the
System.ComponentModel namespace. It should provide most of the
functionality that you are looking for.

If you want to modify your objects from code, and have the grid update,
then you should probably implement the INotifyPropertyChanged interface on
your class.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Merk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm new to .NET (using 2.0) and was wondering how to go about binding a
> collection of custom classes to a DataGrid.
>
> The class exposes 5 read-only String properties. I would like for each of
> these properties to appear in a column in the DataGrid.
>
> The end result would be that when the collection has 35 objects in it, the
> DataGrid would have 35 rows and 5 columns (after being bound to the
> collection).
>
> Specifically -
> 1. which collection class could/should I use (or do I need to roll my own
> to make it "bindable")?
> and/or
> 2. how do I make my objects in that collection "bindable" to the
> DataGrid?
>
> Thanks.
>



 
Reply With Quote
 
Merk
Guest
Posts: n/a
 
      9th Sep 2006
Yes - it helps a lot - exactly the level of direction I was looking for.
Thanks.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView + Binding a Collection of Objects + RowUpdating Spam Catcher Microsoft ASP .NET 0 23rd May 2006 06:02 AM
Binding a data source to a collection of objects Christoph Boget Microsoft ASP .NET 7 20th Sep 2004 03:21 PM
Datagrid: Binding to custom collection Carlos Campos Microsoft Dot NET Framework Forms 3 24th Jun 2004 05:09 PM
binding a grid to a collection of custom objects Microsoft C# .NET 1 19th May 2004 02:11 PM
Help: Data Binding to Custom Collection Shrage Smilowitz Microsoft ASP .NET 2 31st Oct 2003 12:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:52 AM.