473,465 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

loop through listbox values

yue
Hi,

How do I loop through listbox items?

Thanks,

yue
Nov 15 '05 #1
7 66778
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.