Re: Cannot Refer to DropDownList Items by Index

From: Andy Gaskell (pubb)
Date: 05/24/04


Date: Mon, 24 May 2004 16:12:51 -0500

Yes you can refer to the items by index, and there is an indexer. Sometimes
the Command Window sucks...

Confirm that ((DropDownList)myControl).Items.Count is 2 and also confirm
that myIndex is 0 or 1.

"Eric" <anonymous@discussions.microsoft.com> wrote in message
news:FD2FB020-C755-4C2A-9193-EF3C1B625243@microsoft.com...
> Hello All...
>
> I have a C# class library with a function that selects the appropriate
gender for a DropDownList. At run-time, it errors off. The offending line
of code is (where "myControl" is the passed in drop down list):
>
> ((DropDownList)myControl).Items[myIndex].Selected = true;
>
> When looking in the Immediate Window, I try to access the first list item,
but I get an error:
> ? ((DropDownList)myControl).Items[0]
> error: object '(DropDownList)Control.Items' doesn't have an indexer
>
> This is quite odd, seeing as though the SelectedIndex property does return
a value:
> ? ((DropDownList)myControl).SelectedIndex
> 3
>
> Is it not, then, safe to assume that this control DOES have an indexer, so
you can refer to list items by index? Is there a work-around that will let
me access this by index? Or will this just be added to my "Why I Should Use
VB.NET Instead" list? :-)
>
> Thanks in advance,
>
> Eric



Relevant Pages

  • A property or indexer may not be passed as an out or ref parameter
    ... resides in a dataset and I refer to the datatable in the dataset using ... "A property or indexer may not be passed as an out or ref parameter?" ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: DataRow["columnname", DataRowVersion.Original] error in VS IDE
    ... >I am trying to examine the value of a column in the command window by using ... > object 'someRow' doesn't have an indexer. ... > The overload without the version info works like a charm. ... > Infinity Info Systems ...
    (microsoft.public.dotnet.framework.adonet)
  • "My Documents" directory
    ... How can I refer to this? ... it's for me from the command window. ... Mark Stanton ... One small step for mankind... ...
    (microsoft.public.fox.programmer.exchange)
  • Re: "My Documents" directory
    ... cHomeDir = GETENVmight help. ... > How can I refer to this? ... > It's not for end users, it's for me from the command window. ... > Mark Stanton ...
    (microsoft.public.fox.programmer.exchange)
  • Re: "My Documents" directory
    ... Neil ... > How can I refer to this? ... > It's not for end users, it's for me from the command window. ... > Mark Stanton ...
    (microsoft.public.fox.programmer.exchange)