473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

loop through listbox values

yue
Hi,

How do I loop through listbox items?

Thanks,

yue
Nov 15 '05 #1
7 66773
This will serve.

foreach(object o in listBox1.Items)

Sam
"yue" <yu*@mail.com> wrote in message
news:0c****************************@phx.gbl...
Hi,

How do I loop through listbox items?

Thanks,

yue

Nov 15 '05 #2
yue
Hi,

That did not work also.

yue
-----Original Message-----
try:

foreach (string s in listBox1.Items)

"yue" <yu*@hotmail.com> wrote in message
news:4d****************************@phx.gbl...
Hi Sam,
i have done this but cant get the row values.

Please help,

thanks,

yue
>-----Original Message-----
>This will serve.
>
> foreach(object o in listBox1.Items)
>
>Sam
>
>
>"yue" <yu*@mail.com> wrote in message
>news:0c****************************@phx.gbl...
>> Hi,
>>
>> How do I loop through listbox items?
>>
>> Thanks,
>>
>> yue
>
>
>.
>

.

Nov 15 '05 #3
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

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" <yu*@mail.com> wrote in message
news:0c****************************@phx.gbl...
Hi,

How do I loop through listbox items?

Thanks,

yue

Nov 15 '05 #4
yue
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
-----Original Message-----
ListBox items accept objects of any type as elements. Find where theelements are being added, and use that class in the foreach. For instance,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" <yu*@mail.com> wrote in message
news:0c****************************@phx.gbl...
Hi,

How do I loop through listbox items?

Thanks,

yue

.

Nov 15 '05 #5
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" <yu*@hotmail.com> wrote in message
news:4e****************************@phx.gbl...
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
-----Original Message-----
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

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" <yu*@mail.com> wrote in message
news:0c****************************@phx.gbl...
Hi,

How do I loop through listbox items?

Thanks,

yue

.

Nov 15 '05 #6
yue
Chris,

Thank You for all your help.

I will try this.

yue
-----Original Message-----
In this case, you ought to loop through the datasource instead of the listbox's collection. For a DataTable, this is

foreach (DataRow row in dataTable1.Rows) {}

It ought to be similar for a DataView.

Chris

"yue" <yu*@hotmail.com> wrote in message
news:4e****************************@phx.gbl...
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
>-----Original Message-----
>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
>
>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" <yu*@mail.com> wrote in message
>news:0c****************************@phx.gbl...
>> Hi,
>>
>> How do I loop through listbox items?
>>
>> Thanks,
>>
>> yue
>
>
>.
>

.

Nov 15 '05 #7
On Wed, 30 Jul 2003 08:22:31 -0700, in the
microsoft.public.dotnet.languages.csharp group, yue said...
How do I loop through listbox items?


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.Items Property you will find one example of
how to iterate through the list.

In addition, follow through from CollectionBaseClass, 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.

Gerald
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Christina | last post by:
I have a post-form that holds a listbox with mulitple selected items. When the form is posted to the server ASP file, I want to loop through the selected items, to insert each of them into a table....
17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
4
by: Ryan Ternier | last post by:
Thanks for the previous help guys! I got my list box issue working, but now i'm trying to loop through all the items in my page. I want to find each listbox, once I do i strip the ID down to...
6
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
2
by: Jeff | last post by:
....another beginner question - using visual web 2005 with VB I have 20 labels - lbl1 through lbl20 I have a listbox containing values 1 through 20 I need to make label 1 through the...
0
by: =?Utf-8?B?UGF1bA==?= | last post by:
I have a ListBox server control named "lb_dates" with a SelectionMode of "Multiple". The user can select multiple dates from the listbox. I have ObjectDataSource named "ods_rfq" with a...
2
OuTCasT
by: OuTCasT | last post by:
I have a listbox on my form that has items that the user has chosen, i need to loop through the listbox and get the values and insert them into a sql table. Can anyone hlp?
1
OuTCasT
by: OuTCasT | last post by:
I have bound a listbox with a dataTable Now i want to move the values from the listbox to another listbox. i have changed the selectionMode of the listbox to multiple. So they choose multiple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.