I'm using the new BindingList generic class in a collection class. For those
not familiar with BindingLists, they are similar to generic ArrayLists, but
they implement the IBindingList interface, which means they support two-way
data binding.
As my class is written, the collection's BindingList is exposed as a
property. That means I have to bind to the property, rather than the
collection, like this:
dataGridView1.DataSource = myCollection.BindingList;
I'd rather bind directly to the collection, rather than to a property, like
this:
dataGridView1.DataSource = myCollection;
Is there a way to accomplish this with a BindingList? Or, is there a base
class that implements IBindingList that I could derive from? Thanks in
advance for your help.
David Veeneman
Foresight Systems
Bart Mermuys - 27 Dec 2005 17:08 GMT
Hi,
> I'm using the new BindingList generic class in a collection class. For
> those not familiar with BindingLists, they are similar to generic
[quoted text clipped - 14 lines]
> Is there a way to accomplish this with a BindingList? Or, is there a base
> class that implements IBindingList that I could derive from?
Maybe i'm missing something but you can derive from BindingList<T>, eg:
public class PersonCollection : BindingList<Person>
{
}
HTH,
Greetings
Thanks in
> advance for your help.
>
> David Veeneman
> Foresight Systems
David Veeneman - 27 Dec 2005 18:43 GMT
So simple, I completely overlooked it! Thanks.
Michael S - 29 Dec 2005 01:44 GMT
> So simple, I completely overlooked it! Thanks.
Yep.
Inheritance is somewhat hard to grasp for some. Generics often more so. We
all master them some day and know the idioms and their use, and when not to.
But combined they make for some serious braindamage when thinking on how to
solve stuff, while the solution often turn out to be quite simple..
I was lost at this one and was about to submit a 'it can't be done' post
when I saw the solution...
All too easy..
Happy Coding
- Michael S
W.Meints - 27 Dec 2005 19:27 GMT
Hi David,
Assuming you have implemented a custom collection to keep track of your data.
You can replace the collection with a declaration like this:
BindingList<Person> persons = new BindingList<Person>();
And bind it to the datagridview
DataGridView1.DataSource = persons;

Signature
Best regards,
W.Meints
> Hi,
>
[quoted text clipped - 31 lines]
> > David Veeneman
> > Foresight Systems