fire event when listsize changes

T

Tarscher

Hi all,

I'm a c# sharp beginner and need to fire an event when a list changes
in size (element added or removed). Can i make my own event that fires
when this happenes?

Thanks in advance
Stijn
 
Z

zacks

Hi all,

I'm a c# sharp beginner and need to fire an event when a list changes
in size (element added or removed). Can i make my own event that fires
when this happenes?

Thanks in advance
Stijn

Assuming you mean a ListView control. There does not appear to be an
event that fires when a new item is added or removed. But since you
will be doing either of those yourself in the code, all you need to do
is setup a private method to perform the action you desire and invoke
that method after you invoke either the .Add or .Remove methods.
 
T

Tarscher

Assuming you mean a ListView control. There does not appear to be an
event that fires when a new item is added or removed. But since you
will be doing either of those yourself in the code, all you need to do
is setup a private method to perform the action you desire and invoke
that method after you invoke either the .Add or .Remove methods.

I don't mean a ListView. I mean the List (like in array).

i have several lists and want to be informed when the size of the list
changes. My question is if I can make an event myself that informs me
when the size changes.

Stijn
 
N

Nicholas Paldino [.NET/C# MVP]

Stijin,

Yes, you can, although you would have to derive from a list to do so.
You might want to just use the BindingList<T> class, as it has an AddingNew
and ListChanged events which you can easily use to monitor change detection.
 

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