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?

[310 byte] By [ThomasLau] at [2007-12-21]
# 1

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.

PeterRitchie at 2007-9-10 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 2
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)

joeycalisay at 2007-9-10 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 3

thanks a lot.

It's a good ideal.Using your mothed I am successful to make the collection property notify the change to control when it add or remove a element.I created a class derived from System.Collections.ObjectModel.Collection<T> and declare a System.ComponentModel.CollectionChangeEventHandle event in it.But when an element's property changed in the collecion the control doesn't still change .

Best regards

ThomasLau at 2007-9-10 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 4

joeycalisay wrote:
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)

Thanks, I wanna implement it on run-time but design-time.

ThomasLau at 2007-9-10 > top of Msdn Tech,Windows Forms,Windows Forms Designer...
# 5
Try adding this.Invalidate() as the last line of your set{} block.
JRQ at 2007-9-10 > top of Msdn Tech,Windows Forms,Windows Forms Designer...