IBindingList implementation
-
Hello, I have a generic class BindingCollection<T> : IBindingList The purpose of this class is to collect Business Objects and functionality around them (LoadAll, New ...). I implemented IBindingList so I could be able to bind it to a DataGridView (with BindingSource) and when changes occur to the BindingCollection, the DataGridView would notice and update itself and vice versa. I think that so far, this is a logical setup, no? Now I'm wondering how I should implement the IBindingList interface methods. Should I make a class-variable BindingList<T> list and when, for example, AddIndex(...) is called, do something like
public void AddIndex(PropertyDescriptor property) { ((IBindingList)list).AddIndex(property); }
At the moment I implemented all interface methods in a similar way, but even though my inner list gets updated nicely, the DataGridView still doesn't notice any changes nor does it update it's presented data. Any help would be very welcome, because I have been struggling with this problem for quite a while, and you could help me a lot further. Greets, Bert -
Hello, I have a generic class BindingCollection<T> : IBindingList The purpose of this class is to collect Business Objects and functionality around them (LoadAll, New ...). I implemented IBindingList so I could be able to bind it to a DataGridView (with BindingSource) and when changes occur to the BindingCollection, the DataGridView would notice and update itself and vice versa. I think that so far, this is a logical setup, no? Now I'm wondering how I should implement the IBindingList interface methods. Should I make a class-variable BindingList<T> list and when, for example, AddIndex(...) is called, do something like
public void AddIndex(PropertyDescriptor property) { ((IBindingList)list).AddIndex(property); }
At the moment I implemented all interface methods in a similar way, but even though my inner list gets updated nicely, the DataGridView still doesn't notice any changes nor does it update it's presented data. Any help would be very welcome, because I have been struggling with this problem for quite a while, and you could help me a lot further. Greets, BertHi, have you bound the ListChanged event of the inner class? If not then do so and rethrow the event within your class. Robert
-
Hello, I have a generic class BindingCollection<T> : IBindingList The purpose of this class is to collect Business Objects and functionality around them (LoadAll, New ...). I implemented IBindingList so I could be able to bind it to a DataGridView (with BindingSource) and when changes occur to the BindingCollection, the DataGridView would notice and update itself and vice versa. I think that so far, this is a logical setup, no? Now I'm wondering how I should implement the IBindingList interface methods. Should I make a class-variable BindingList<T> list and when, for example, AddIndex(...) is called, do something like
public void AddIndex(PropertyDescriptor property) { ((IBindingList)list).AddIndex(property); }
At the moment I implemented all interface methods in a similar way, but even though my inner list gets updated nicely, the DataGridView still doesn't notice any changes nor does it update it's presented data. Any help would be very welcome, because I have been struggling with this problem for quite a while, and you could help me a lot further. Greets, BertIndexes you have to manage yourself (I looked into implementing the same thing), if you look at the source code in Reflector (if you can get your head around the way things have been implemented), then you'll see that (I think it was anyway) AddIndex will throw a NotImplemented exception. You basically have to manage your own indexes, I seem to remember there was one method which you could override which would be fired when anything changed. Can't remember the name of it but if you want it I can dig it up tomorrow sometime when I put the other disk back in (and when I have time). Possibly the simplest way to maintain indexes is to have a dictionary object to provide looking up the indexes. Maybe, I'm not sure though. There doesn't seem to be very much documentation on the subject at all. Don't hesitate to ask if you want further help as I did spend quite a bit of time figuring out what was going on (just got to remember what it was :rolleyes:).
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed