Item.Selected property not listed? RRS feed

  • Question

  • How do I check if listbox item is selected if Item.Selected property not listed?  VS Community 2019
    Tuesday, August 27, 2019 11:47 PM

All replies

  • Hi RichardBunneBSc,

    Welcome to MSDN forum.

    For your requirement, please have a try to below methods:

    ## Use SelectedIndex property, if the item is not selected, the value will be -1

    if (listBox1.SelectedIndex == -1)
        MessageBox.Show("please select item");

    ## Use "try...catch..." block, when the selected.item is null, the program will throw a exception then abort the process, the block could catch or ignore the exception and the process could continue running

         if (listBox1.SelectedItem.ToString() == "1")
         MessageBox.Show("Please select item");

    Please refer more: try-catch (C# Reference)

    Any feedback will be expected.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, August 28, 2019 4:22 AM