开发者

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 开发者_Python百科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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜