Event after adding an object to a ListBox?

  • Thread starter Thread starter Dirk Behrendt
  • Start date Start date
D

Dirk Behrendt

Hello!

There are a possibility to get informed after adding an object to a ListBox?
I did not find events for that. Maybe I can use another way?

ListBox listBox = new ListBox();
listBox.Items.Add("12345");

---> I need the information that a new item was added to the ListBox.

Thank you!

Bye

Dirk Behrendt
 
You can always implement your own ListBox for that, something like this:

class ListBoxEx : ListBox
{
public void Add(string item)
{
Items.Add(item);
OnItemAdded(EventArgs.Empty);
}

public event EventHandler ItemAdded;
protected virtual void OnItemAdded(EventArgs e)
{
if (ItemAdded != null)
ItemAdded(this, e);
}
}
 
Back
Top