I have a tree in Grid view, bound to a list (which is a custom type derived from BindingList) of objects (which implement INotifyPropertyChanged). One of the columns is of type CheckState (set in code, since the Designer doesn't know about that type), and is bound to an object property which is declared as CheckState. All of these properties default to unchecked.
Here's the behavior: if I check the checkbox on one item, nothing happens (that is, the property on the object does not get set). If I now check the checkbox on a second item, the property on the *first* item is set, but not the property on the second item. If I check a third item, the second item will get set, and so forth. When the property is modified, I am firing the PropertyNotified event like I'm supposed to.
This is pretty clearly something wrong with my code. Any idea what I could be doing to cause this behavior?
Thanks, Aaron
Thanks, but my understanding is that BindingList<T> will automatically subscribe to the PropertyChanged event of any objects added to it (as per the example at http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx).
Could the problem be that I've actually got two levels of lists? In order to get the tree to show two levels, I have to actually provide it three levels of data, meaning that I have a list containing a list containing objects. If the BindingList behaves as I expect, it will catch the property-changed notifications from the Customer objects and translate them into events through its IBindingList interface, but maybe the outer list won't transfer those to the tree view?
I could probably make my BindingList subclass implement INotifyPropertyChanged as well, so that the events would bubble all the way to the top. Do you think this would work?
Aaron
Hi Aaron,
In this example, the Customer class is implementing INotifyPropertyChanged, which is good. But the problem is that no one is listening to this notification. The BindingList has to hook into this notification on each item in the list and when it fires, it has to fire ListChanged on itself to notify the DotNet BindingManager that a change occurred.
Where did this sample come from? I took a look and I don't see it under the WinTree samples installed with NetAdvantage. If this is one of our samples, then it needs to be updated to work properly because it's incomplete.
The attached archive contains a modification of the WinTree_Bound_To_List sample that illustrates the issue. I assume you're talking about the update-doesn't-show-until-mouseover problem here, right? The other one is clearly not a bug, just a problem that I'd like your input on.
There are two possibilities here:
1) The Data Source is not sending the property notifications to the tree to let it know that the data has changed.
2) This is a bug in the tree.
I'm pretty sure this works when using a DataTable, so my guess is that there is some problem with the implementation of your custom data source and the notification is not properly getting bubbled up. Can you reproduced this issue in a small sample project and post it here so we can check it out?
No more ideas on this? I think I could hack around this issue if I had to, but I'd rather not if there's a "right" answer.