"yue" <yue@mail.com > wrote in message
news:0c7501c356 ae$652f1af0$a60 1280a@phx.gbl.. .[color=blue]
> Hi,
>
> How do I loop through listbox items?
>
> Thanks,
>
> yue[/color]
ListBox items accept objects of any type as elements. Find where the
elements are being added, and use that class in the foreach. For instance,
if you do this
foreach (MyCustomClass item in listBox1.Items) {
}
Chris
"yue" <yue@mail.com > wrote in message
news:0c7501c356 ae$652f1af0$a60 1280a@phx.gbl.. .[color=blue]
> Hi,
>
> How do I loop through listbox items?
>
> Thanks,
>
> yue[/color]
Chris,
This is good if you use the add method of the listbox.
I set the listbox Datasource on a filtered DataTable.
This is why i need to loop through the listbox and get the
elements.
Is there no easy way to do this? This is so frustrating to
me...
yue[color=blue]
>-----Original Message-----
>ListBox items accept objects of any type as elements.[/color]
Find where the[color=blue]
>elements are being added, and use that class in the[/color]
foreach. For instance,[color=blue]
>if you do this
>
>listBox1.Items .Add(new MyCustomClass(" Hi", 3, true));
>
>then you would do this to get the values
>
>foreach (MyCustomClass item in listBox1.Items) {
>}
>
>Chris
>
>"yue" <yue@mail.com > wrote in message
>news:0c7501c35 6ae$652f1af0$a6 01280a@phx.gbl. ..[color=green]
>> Hi,
>>
>> How do I loop through listbox items?
>>
>> Thanks,
>>
>> yue[/color]
>
>
>.
>[/color]
In this case, you ought to loop through the datasource instead of the list
box's collection. For a DataTable, this is
foreach (DataRow row in dataTable1.Rows ) {}
It ought to be similar for a DataView.
Chris
"yue" <yue@hotmail.co m> wrote in message
news:4ebd01c356 be$4e392a10$a00 1280a@phx.gbl.. .[color=blue]
> Chris,
> This is good if you use the add method of the listbox.
> I set the listbox Datasource on a filtered DataTable.
> This is why i need to loop through the listbox and get the
> elements.
>
> Is there no easy way to do this? This is so frustrating to
> me...
>
> yue[color=green]
> >-----Original Message-----
> >ListBox items accept objects of any type as elements.[/color]
> Find where the[color=green]
> >elements are being added, and use that class in the[/color]
> foreach. For instance,[color=green]
> >if you do this
> >
> >listBox1.Items .Add(new MyCustomClass(" Hi", 3, true));
> >
> >then you would do this to get the values
> >
> >foreach (MyCustomClass item in listBox1.Items) {
> >}
> >
> >Chris
> >
> >"yue" <yue@mail.com > wrote in message
> >news:0c7501c35 6ae$652f1af0$a6 01280a@phx.gbl. ..[color=darkred]
> >> Hi,
> >>
> >> How do I loop through listbox items?
> >>
> >> Thanks,
> >>
> >> yue[/color]
> >
> >
> >.
> >[/color][/color]
yue[color=blue]
>-----Original Message-----
>In this case, you ought to loop through the datasource[/color]
instead of the list[color=blue]
>box's collection. For a DataTable, this is
>
>foreach (DataRow row in dataTable1.Rows ) {}
>
>It ought to be similar for a DataView.
>
>Chris
>
>"yue" <yue@hotmail.co m> wrote in message
>news:4ebd01c35 6be$4e392a10$a0 01280a@phx.gbl. ..[color=green]
>> Chris,
>> This is good if you use the add method of the listbox.
>> I set the listbox Datasource on a filtered DataTable.
>> This is why i need to loop through the listbox and get[/color][/color]
the[color=blue][color=green]
>> elements.
>>
>> Is there no easy way to do this? This is so frustrating[/color][/color]
to[color=blue][color=green]
>> me...
>>
>> yue[color=darkred]
>> >-----Original Message-----
>> >ListBox items accept objects of any type as elements.[/color]
>> Find where the[color=darkred]
>> >elements are being added, and use that class in the[/color]
>> foreach. For instance,[color=darkred]
>> >if you do this
>> >
>> >listBox1.Items .Add(new MyCustomClass(" Hi", 3, true));
>> >
>> >then you would do this to get the values
>> >
>> >foreach (MyCustomClass item in listBox1.Items) {
>> >}
>> >
>> >Chris
>> >
>> >"yue" <yue@mail.com > wrote in message
>> >news:0c7501c35 6ae$652f1af0$a6 01280a@phx.gbl. ..
>> >> Hi,
>> >>
>> >> How do I loop through listbox items?
>> >>
>> >> Thanks,
>> >>
>> >> yue
>> >
>> >
>> >.
>> >[/color][/color]
>
>
>.
>[/color]
On Wed, 30 Jul 2003 08:22:31 -0700, in the
microsoft.publi c.dotnet.langua ges.csharp group, yue said...[color=blue]
> How do I loop through listbox items?[/color]
Items is a property of a listBox containing a collection. If you follow
the links from ListBox Class to ListBox Members to Items (inherited from
ListControl) to ListControl.Ite ms Property you will find one example of
how to iterate through the list.
In addition, follow through from CollectionBaseC lass, CollectionBase
Members to GetEnumerator which describes also MoveNext, Current and
Reset.
So essentially you have choices of for, foreach and GetEnumerator
approaches to do what you want to do.
Comment