Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
850
Bizarre behavior with bound checkboxes
posted

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

Parents
  • 850
    posted

    OK, I reread your previous post. You're correct, if I had a Customer at each level of the tree and a Customer could have a list of sub-Customers, that would probably solve the problem. Unfortunately, I don't want a customer at each level; the collections have their own fields (represented by Index in this example) that I need to display.

    So, I've created a base class named TreeNodeOb that implements INotifyPropertyChanged and provides a BindingList<TreeNodeOb> as one of its properties, and derived both Customer and CustomerCollection from that class. Now, I have more or less what you suggested - a data structure with an object at each level that provides property-changed notifications. I now need to bind the tree to the Children property of my base-level object, but that's OK.

    So, that's good progress, thank you. That just leaves my secondary question: is there any way to support recursive updates from the higher-level checkboxes? That is, if I check a group, I want to check all the items contained within that group. Unfortunately, since the update doesn't occur until I leave the cell, I have no way to make that happen immediately. Is there any way to force the update to occur immediately? Can I detect the click in the checkbox somehow and force a refresh?

    Thanks,
       Aaron

Reply Children