HelpNeeder
HelpNeeder

Reputation: 6480

Is there an EventHandler in which I can check if ListBox doesn't contain any items?

I'm trying to avoid having the same code in multiple places. Which event handler would let me to check if I have any items in my ListBox on the fly?

This is how I check if I have any items in ListBox:

if (lbMessage.Items.Count > 0)
{
    btnStart.Enabled = true;
}
else
{
    btnStart.Enabled = false;
}

Upvotes: 0

Views: 57

Answers (1)

Samuel Slade
Samuel Slade

Reputation: 8613

There is no event for such an occurrence (for a list of available events, check out the MSDN Documentation for this control). To make your code more re-usable, you could use a property, such as:

public bool ListBoxHasItems
{
    get { return lbMessage.Items.Count > 0; }
}

Then you can just call that property each time you want to check if there are any items.

Upvotes: 2

Related Questions