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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Karan PatelPosted Mar 2, 2010, 11:12 AM
MessageBox.Show("index of apple is:" + i.ToString());
Raaj KumarPosted Mar 2, 2010, 10:10 AM
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
denny simonPosted Mar 2, 2010, 9:07 AM
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
Syed ShakeerPosted Mar 2, 2010, 8:43 AM
There is a SelectedIndex Property for a ComboBox.