How do collection items notify a change to control.
hi,
I create a winform control with collection property.The collection property include some type object.But when I modify the object's property in the collection on run-time the control doesn't change.How to notify control to change when object's property change in the collection property?
What kind of control is it, a UserControl?
If the display of your control is dependant on the contents of a collection you'll need to force the control to repaint whenever the collection changes. You can force a repaint with the Control.Invalidate() method.
If your collection is a public property you'll need to do a bit of work to be informed of any changes to that collection outside of your control class. One way is to implement your own collection class. The documentation for Collection.InsertItem shows an example of raising an event when InsertItem is called.
i prefer using IComponentChangeService to notify the designer of the changes so it can invalidate whatever it needs to. so when modifying any UI related property of the control, i prefer to change them through TypeDescriptor which automatically notifies ComponentChangeService of the designerhost
something like:
TypeDescriptor.GetProperties(component, "myproperty").SetValue(value)