Home All Groups Group Topic Archive Search About

How do I know my collection was modified?

Author
7 Sep 2006 2:49 PM
Steve Barnett
I have a user control that includes a StringCollection. I provide my users
with a property that retrieves a reference to the string collection so they
can add and remove items from it, just as you would do if this were, for
example, a listbox.

What I can't see is any way for my user control to detect that the
StringCollection was modified. Is there any way (short of overriding all the
methods) that I can be informed if the collection is modified so I can
redraw my control?

Thanks
Steve

Author
7 Sep 2006 3:12 PM
Claes Bergefall
Doesn't look like you can. I would inherit a new class from
System.Collections.ObjectModel.Collection<T> instead. That one has proteced
methods that you can override to handle insert, remove and set.

   /claes


Show quote
"Steve Barnett" <non***@nodomain.com> wrote in message
news:eYHsJzo0GHA.4796@TK2MSFTNGP06.phx.gbl...
>I have a user control that includes a StringCollection. I provide my users
>with a property that retrieves a reference to the string collection so they
>can add and remove items from it, just as you would do if this were, for
>example, a listbox.
>
> What I can't see is any way for my user control to detect that the
> StringCollection was modified. Is there any way (short of overriding all
> the methods) that I can be informed if the collection is modified so I can
> redraw my control?
>
> Thanks
> Steve
>
Author
7 Sep 2006 4:03 PM
Steve Barnett
Much appreciated  - I thought it was just me being dumb. I'll go with your
suggestion.

Thanks
Steve


Show quote
"Claes Bergefall" <louplou@nospam.nospam> wrote in message
news:eo$4W%23o0GHA.3476@TK2MSFTNGP04.phx.gbl...
> Doesn't look like you can. I would inherit a new class from
> System.Collections.ObjectModel.Collection<T> instead. That one has
> proteced methods that you can override to handle insert, remove and set.
>
>   /claes
>
>
> "Steve Barnett" <non***@nodomain.com> wrote in message
> news:eYHsJzo0GHA.4796@TK2MSFTNGP06.phx.gbl...
>>I have a user control that includes a StringCollection. I provide my users
>>with a property that retrieves a reference to the string collection so
>>they can add and remove items from it, just as you would do if this were,
>>for example, a listbox.
>>
>> What I can't see is any way for my user control to detect that the
>> StringCollection was modified. Is there any way (short of overriding all
>> the methods) that I can be informed if the collection is modified so I
>> can redraw my control?
>>
>> Thanks
>> Steve
>>
>
>
Author
7 Sep 2006 6:51 PM
Ben Voigt
Show quote
"Steve Barnett" <non***@nodomain.com> wrote in message
news:O8qn0cp0GHA.2072@TK2MSFTNGP06.phx.gbl...
> Much appreciated  - I thought it was just me being dumb. I'll go with your
> suggestion.
>
> Thanks
> Steve
>
>
> "Claes Bergefall" <louplou@nospam.nospam> wrote in message
> news:eo$4W%23o0GHA.3476@TK2MSFTNGP04.phx.gbl...
>> Doesn't look like you can. I would inherit a new class from
>> System.Collections.ObjectModel.Collection<T> instead. That one has
>> proteced methods that you can override to handle insert, remove and set.
>>
>>   /claes
>>

You may try BindingList<T> instead, and subscribe to the ListChanged event

AddThis Social Bookmark Button