473,408 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

BindingListOfT

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
Dec 27 '05 #1
4 1374
Hi,

"David Veeneman" <da****@nospam.com> wrote in message
news:uV*************@tk2msftngp13.phx.gbl...
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?
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

Dec 27 '05 #2
So simple, I completely overlooked it! Thanks.
Dec 27 '05 #3
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;
--
Best regards,

W.Meints
"Bart Mermuys" wrote:
Hi,

"David Veeneman" <da****@nospam.com> wrote in message
news:uV*************@tk2msftngp13.phx.gbl...
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?


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


Dec 27 '05 #4
"David Veeneman" <da****@nospam.com> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
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


Dec 29 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.