473,836 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8307
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*****@comcas t.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******** ******@TK2MSFTN GP15.phx.gbl...
"Rob" <rw*****@comcas t.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******** ******@TK2MSFTN GP14.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.Ite ms
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******** ********@TK2MSF TNGP10.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.Ite ms
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
3701
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 when iteration. here is the wrong way I did: lst = for i in lst: print i if i == 2:
12
2415
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 will pull out the customer details each time their is an inventory item listed....I need to get the customer out ONCE and list his items....is there an elegant way to do this: Here is the table: Cust-Invent Table
26
32165
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. Christina
5
392
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 called and then inherited collection disapears. (The same problem occurs regardless of which collection type I inherit) I cannot figure this out as I still have a ref to the object that inherits the collection. I think it is something like the...
1
1707
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 the 'locations selected' (cart) listbox. I have a hirarchy of locations - main locations and sub locations. main locations being the parent locations, and the sub locations being the child locations. I want to be able to check to see if the...
6
3234
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 to do such a thing? Thanks,
8
5288
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 list boxes which will in turn populate a third list box with a numeric number when you click a button. Then I have a calculate button that is supposed to add all the numbers that were populated in the third list box. I can only get the first item and...
5
13352
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 (there's no guess for how many items a user can add as well), I want my external process run one by one. Process must run for item1 then item2 when item1's work finishes....until the last listbox item.
16
1772
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 NotesList.Items.Add(Me.Browser.Document.GetElementsByTagName("ul").Item(0).GetElementsByTagName("li").Item(index).InnerText) Next index
0
9816
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9668
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10840
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10254
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9371
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6978
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3112
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.