HELP: Finding index of a SelectedValue in combobox ??

  • Thread starter Thread starter KlaasIMN
  • Start date Start date
K

KlaasIMN

Using a combobox I want to retrieve the index of a given value in a
combobox.

object sel = combo.SelectedValue;

string selectedvalue = sel.ToString();
ComboBox.ObjectCollection items = combo.Items;

int i = items.IndexOf(sel);

returns -1 into despite the fact that [sel] does exist in the
combobox.

What is the problem here ?

Thanks.
 
KlassIMN,

Instead of trying to find it yourself, why not just use the
SelectedIndex property?

Hope this helps.
 
Back
Top