|
-
Oct 7th, 2009, 06:10 PM
#1
Thread Starter
Junior Member
Notifying changes in the column collection in custom objects
Hello
Suppose that I have a class that implements the IComponent, IBindingList, ITypedList and the INotifyChange interfaces and then I databound an object of this class to a DataGridView control. I would like to know if there is a way to notify the client that the available "column" collection has changed.
Please notice that I am not talking about notifying that the rows has change, but that the "schema" has changed. The number of properties, or the datatype of them.
For example, if initially at runtime the control displays 3 columns and then the underlying object adds a new available property, the DataGrid would still display 3 columns unless somehow the control is notified to repopulate its column collection.
Although rebinding would do the trick, I wonder if there is a mecanism of notification for this cases.
Thanks a lot.
-
Oct 7th, 2009, 11:20 PM
#2
Re: Notifying changes in the column collection in custom objects
When you raise the IBindingList.ListChanged event you specify a ListChangedEventArgs object, which has a ListChangedType property. You can set that property to one of the PropertyDescriptorX values. I haven't tested it but I think that that should prompt a DataGridView to regenerate its columns if its AutoGenerateColumns property is set to True. Note that if you call ResetBindings on a BindingSource and pass True as an argument, that BindingSource raises a ListChanged event with PropertyDescriptorChanged as the ListChangedType value.
-
Oct 8th, 2009, 01:15 PM
#3
Thread Starter
Junior Member
Re: Notifying changes in the column collection in custom objects
Thanks. I am using a class derived from BindingList and I've got it partially working by calling MyBase.OnListChanged(). When adding a new column it works fine, but when calling that method when a column is removed, it raises the ArgumentException stating "Cannot bind to the property or column Field1 on the DataSource" -where Field1 is the column that has just been removed.
I would appreciate further suggestions.
Thanks a lot.
-
Oct 8th, 2009, 05:52 PM
#4
Re: Notifying changes in the column collection in custom objects
I'm not going to provide further suggestions when I don;t even know exactly how you've implemented the last one. This is where you provide the code you've written so I can see what you've done, whether there are any obvious issues with and whether I can reproduce your problem by running it myself. It's a waste of time my looking further afield for a solution if you already have one but you just haven't implemented it properly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|