1.You should check in debug the value of
comboBox1.SelectedValue
, maybe when you init your control you forgot to set a default selected value;
2.You should manage also the case when no value from the list is selected, and in that case
comboBox1.SelectedValue
will have as value the
Empty string
, and because your int ins in hexa format (new info that you did not added in your initial question after I gave you my first version of the solution) you should use
int.Parse
like in the next example:
int a = 0;
string UserId = comboBox1.SelectedValue.ToString();
if(UserId.Length > 0)
{
a = int.Parse(UserId, NumberStyles.AllowHexSpecifier);
}