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

Re: dropdownlist - index of an item by Herfried

Herfried
Sun Apr 03 15:54:07 CDT 2005

"Lubomir" <Lubomir@discussions.microsoft.com> schrieb:
> 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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Re: dropdownlist - index of an item by Lubomir

Lubomir
Sun Apr 03 18:05:02 CDT 2005

"Herfried K. Wagner [MVP]" wrote:

> "Lubomir" <Lubomir@discussions.microsoft.com> schrieb:
> > 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.
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://classicvb.org/petition/>
>

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.