problem to update control when collection changed

  • Thread starter Thread starter --== Alain ==--
  • Start date Start date
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.
 
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
 
Back
Top