SA.
SA.

Reputation: 752

listbox not showing error when empty

i am using listbox to get the input from user through textbox. if user gives input through textbox i can parse the value from listbox and do my operations. now if user didnot give nay input, then listbox doesn't contain anything. i want that if listbox is empty it should show error in msg box.. i am trying my code but it is not working..

string text1 = lstboxbulkto.ToString();
                if (lstboxbulkto.ToString().Equals(null))
                {
                    MessageBox.Show("hiii");
                }

where lstboxbulkto is the name of the listbox. how can this be done.

Upvotes: 0

Views: 4445

Answers (1)

keyboardP
keyboardP

Reputation: 69372

To check if a Listbox is empty, you can use the Listbox.Items.Count property. If the value is 0, then the listbox is empty.

if(lstboxbulkto.Items.Count == 0)
   MessageBox.Show("hiii");

Upvotes: 5

Related Questions