Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys, I've got a Listbox called lst_Pending and it has two items, True and False. The list box is a part of a form and I need to when submit is clicked if you haven't selected true or false you'll receive an error message asking you that it is necessary to pick one. I've never really used list boxes so this is why I'm not sure.

Would there be any better alternatives to using a Listbox for something that's true or false?
Posted
Updated 3-Mar-14 22:15pm
v2
Comments
Vedat Ozan Oner 4-Mar-14 4:33am    
CheckBox in here: http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox%28v=vs.110%29.aspx

1 solution

Try this for listbox
C#
private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                 //your code logic
            }
            else
            {
                MessageBox.Show("Please select anyone");
            }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900