Search code examples
c#comboboxselectedvalue

Checking a Selected value in the combobox


hi all i was trying to check if a certain selected value in a combobox has been selected i've been trying something like this :

if (Type_CB.SelectedValue == 3)
        {
         ///Do some Code
        }

but it doesn't seem to work

so is there is any idea


Solution

  • All the above comments and answers are correct. In your case, I assume you have added manually some number in your comboBox. Therefore the following would solve your problem:

    string value = Type_CB.SelectedItem.ToString();
    string value2 = "3";
    if (value2 == value)
    {
    do some work
    }