Reputation: 6480
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
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