Вопрос

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

Это было полезно?

Решение

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
}

Другие советы

Because what you want to do is use the SelectedIndex method. Or you can use SelectedItem or SelectedValue if you have the actual item/value, but best thing to use is SelectedIndex.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top