Re: Cannot Refer to DropDownList Items by Index
From: Andy Gaskell (pubb)
Date: 05/24/04
- Next message: keith: "launch an external executable"
- Previous message: C# Learner: "Why Do I Get a Compile Error Here?"
- In reply to: Eric: "Cannot Refer to DropDownList Items by Index"
- Next in thread: clintonG: "Re: Cannot Refer to DropDownList Items by Index"
- Reply: clintonG: "Re: Cannot Refer to DropDownList Items by Index"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: keith: "launch an external executable"
- Previous message: C# Learner: "Why Do I Get a Compile Error Here?"
- In reply to: Eric: "Cannot Refer to DropDownList Items by Index"
- Next in thread: clintonG: "Re: Cannot Refer to DropDownList Items by Index"
- Reply: clintonG: "Re: Cannot Refer to DropDownList Items by Index"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|