Binding Custom Collection/Objects

M

Merk

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

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