473,569 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ 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 66791
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.co m> 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.co m> 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.co m> 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.publi c.dotnet.langua ges.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.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.

Gerald
Nov 15 '05 #8

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

Similar topics

26
32086
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. How do I do that? If I execute the line: Response.Write(Request.Form("ListBox")), I get the list of selected values, separated by commas. ...
17
3094
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) Me.lboxRP.SetSelected(newRPindex, True) When the last line executes, I get an error message:
4
3704
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 find what I need so I can populate a DB. lstTest is dim'd as a ListBox, and I thought I could just do:
6
5193
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 have also tried changing the second ListBox to an HtmlSelect control) using bog standard JavaScript code like so where "used" is the name of my...
0
1679
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 the listbox with no luck and, because it is already bound, I can't just delete the item directly from the listbox without an error (because it already...
2
1326
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 selected value of the listbox visible, but the rest of the labels invisible I'm assuming that the best way to do this is with 2 loops in the listbox click...
0
2123
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 ControlParameter that has a ControlID that points to "lb_dates". The PropertyName of the ControlParameter is "SelectedValue". The user selects two dates...
2
1925
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
2149
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 items and they get moved over to the other listbox. for each item in listbox1.selecteditems listbox2.items.add(item) next
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.