hello all
If I know that one of ComboBox1's Item is "Apple"
how do I know ,what is the ComboBox1 Item index of that "Apple" Item ? (using code )
thank you
denny
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Karan Patel120 reputationPosted Mar 2, 2010, 6:12 AM EST
MessageBox.Show("index of apple is:" + i.ToString());
Syed ShakeerRank #777 · 3K reputationPosted Mar 2, 2010, 3:43 AM EST
There is a SelectedIndex Property for a ComboBox.
denny simon51 reputationPosted Mar 2, 2010, 4:07 AM EST
thank you for the reply but still not answer my question.
Simply I want to load database data from database to form.
One of the data is a object with value "Apple";
I want to place the Text "Apple" as if I use code .
ComboBox1.SelectedIndex=x ;
where x is an integer which I don't know yet .
But I know Exactly that there is an Item in ComboBox1 With value "Apple"
So my question is what code/statement I have to write which return x
thank you
debby
Raaj KumarRank #7,836 · 233 reputationPosted Mar 2, 2010, 5:10 AM EST
You can iterate through the combobox list items and find the index by comparing the item with your name just like this,
void GetComboxIndex()
{
int index= -1;
foreach (var item in comboBox1.Items)
{
if (item.ToString()=="Apple")
{
index++;
break;
}
}
}
Regards,
raaj