HELP: Finding index of a SelectedValue in combobox ??

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.
 
N

Nicholas Paldino [.NET/C# MVP]

KlassIMN,

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

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top