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);
}
}
 

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

Back
Top