How to Loop through Items in a list box

  • Thread starter Thread starter Rob
  • Start date Start date
R

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 !
 
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
 
Rob said:
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?
 
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
 
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
 
Rob said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top