473,320 Members | 2,041 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,320 software developers and data experts.

How to Loop through Items in a list box

Rob
I have a list box where the user may select more than 1 item by clicking on
it. I want to perform a database change to all the items that the user
selected. How do you loop through a list box ?

I assume I could take the key value stored in the list box and perfrom a
databse update as I am looping through the list box.

Thanks !
Nov 21 '05 #1
7 8299
Rob,

The items from a listbox are in a datarowview

Just typed here roughly therefore watch errors

for each drv as datarowview in listbox1.items
'ect
next

I hope this helps,

Cor
Nov 21 '05 #2
"Rob" <rw*****@comcast.net> schrieb:
I have a list box where the user may select more than 1 item by clicking on
it. I want to perform a database change to all the items that the user
selected. How do you loop through a list box ?

I assume I could take the key value stored in the list box and perfrom a
databse update as I am looping through the list box.


Are you using databinding or the 'Items' collection?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Rob
Items collection...

Thanks
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uk**************@TK2MSFTNGP15.phx.gbl...
"Rob" <rw*****@comcast.net> schrieb:
I have a list box where the user may select more than 1 item by clicking
on it. I want to perform a database change to all the items that the
user selected. How do you loop through a list box ?

I assume I could take the key value stored in the list box and perfrom a
databse update as I am looping through the list box.


Are you using databinding or the 'Items' collection?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Rob
Cor,

I tried the following but it did not work. Error appears to be with the
drv in the For Each Statement... as it is underlined.

Thanks,
Rob
Dim drv As DataRowView

For Each drv As DataRowView In lstNo.Items

MsgBox("In Loop")

Next


"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OU**************@TK2MSFTNGP14.phx.gbl...
Rob,

The items from a listbox are in a datarowview

Just typed here roughly therefore watch errors

for each drv as datarowview in listbox1.items
'ect
next

I hope this helps,

Cor

Nov 21 '05 #5
Rob,

Can you try this one for the items, I have somewhere a more difficult one in
mind which gives always problems, because it is hard to find.

For Each item As String In Me.ListBox1.Items
MessageBox.Show(item.ToString)
Next

Sorry, I hope this one helps better.

Cor
Nov 21 '05 #6
Rob schrieb:
Cor,

I tried the following but it did not work. Error appears to be with the
drv in the For Each Statement... as it is underlined.

Thanks,
Rob
Dim drv As DataRowView

For Each drv As DataRowView In lstNo.Items

MsgBox("In Loop")

Next


You declared drv twice.
Armin
Nov 21 '05 #7
Rob
Cor,

This works great !

Thank you very much,

Rob
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Rob,

Can you try this one for the items, I have somewhere a more difficult one
in mind which gives always problems, because it is hard to find.

For Each item As String In Me.ListBox1.Items
MessageBox.Show(item.ToString)
Next

Sorry, I hope this one helps better.

Cor

Nov 21 '05 #8

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

Similar topics

25
by: skull | last post by:
Hi everybody, it is my first post in this newsgroup. I am a newbie for python though I have several years development experience in c++. recently, I was stumped when I tried to del item of a list...
12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
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....
5
by: Alex | last post by:
hi, I have a class that has inheritted a collectionbase class The class works fine generally, I can add items to the collection however whenever I execute a For Each loop, the dispose event is...
1
by: Tim | last post by:
Hi, I'm very new to .NET and am programming in C#. I have a web application where i have two list boxes. Its kind of like a shopping card where you can add items from one 'locations' list box to...
6
by: TCook | last post by:
Hello, I was wondering if anyone has a code snippet for looping through a 'select' control's 'option' elements? Do I have to use an ASP.Net web control such as an asp list control or dropdown...
8
by: Kappadon5 | last post by:
Hello All, I am new to programming and I apologize in advance if I am out of protocol in any way shape or fashion. My problem is that I have a program where you select an option from two different...
5
by: kimiraikkonen | last post by:
Hi, I'm trying to do a batch process for all the items in my listbox1 using "for each...next" ? I'm not well-experienced on this yet, how can i sample this? For example: From item1 to last item...
16
by: Andy B | last post by:
I have the following code inside of a WebBrowser.DocumentCompleted event: For index As Integer = 0 To Me.Browser.Document.GetElementsByTagName("ul").Item(0).GetElementsByTagName("li").Count ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.