problem to update control when collection changed

A

--== Alain ==--

Hi,

I have a collection property in my custom control like this one :

[Category("Behavior")]
[Browsable(true)]
[Description("Column Collection")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ColumnCollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
public ColumnCollection Columns
{
get
{
if (this.m_columns == null)
{
this.m_columns = new ColumnCollection(this);
}
return this.m_columns;
}
}

it works very well, except one thing.

When the number of columns increase or decrease, it should redraw/update
the control, but nothing occurs.
I have to click somewhere on the form to update the control.

I tried to use eventhandlers, but where to use them when there is not
"set" in this property ?

I tried to add them in my ColumnCollection class where is the method to
add column and into the method to remove a column, but nothing worked.

Any ideas ?

thx.

Al.
 
O

Oliver Sturm

Hello ,
I tried to use eventhandlers, but where to use them when there is not
"set" in this property ?

You should derive your collection type from BindingList<T> (or implement
IBindingList if you're on .NET 1), there's an event available on that
class that you can use. Then you hook up to that event when you create the
collection and update your control when you detect changes.
I tried to add them in my ColumnCollection class where is the method to
add column and into the method to remove a column, but nothing worked.

Well, there's no real reason why that couldn't work, so you must have done
something wrong here. If you get the right notifications in the right
places and update your control, why wouldn't that work?


Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top