質問

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