dropdownlist - index of an item

G

Guest

Hi,

I have in a dropdownlist the following values: "aa", "bb", "cc"
I want the item "bb" will be the selected item. I can find it in a
collection by:

myItem = myControl.Items.FindByText("bb");

To make this item selected I can use:
int index = myControl.Items.IndexOf(myItem).

is there any more simple way how to do it? Something like index =
GetIndex("bb"); i can not find such a method.

Thanks,
Lubomir
 
H

Herfried K. Wagner [MVP]

Lubomir said:
I have in a dropdownlist the following values: "aa", "bb", "cc"
I want the item "bb" will be the selected item. I can find it in a
collection by:

myItem = myControl.Items.FindByText("bb");

To make this item selected I can use:
int index = myControl.Items.IndexOf(myItem).

is there any more simple way how to do it? Something like index =
GetIndex("bb"); i can not find such a method.


Take a look at the listbox' 'FindString' and 'FindStringExact' methods.
 
G

Guest

Herfried K. Wagner said:
Take a look at the listbox' 'FindString' and 'FindStringExact' methods.

Thanks,
those methods are probably added to .NET v1.1 as my IDE (MS VS 2002) doesn't
recognize them, neither they are in a help. I have found them in "online
MSDN" however.
 

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