Windows Develop Bookmark and Share   
 index > Windows Forms General > loop through a listbox question
 

loop through a listbox question

i need to loop through a list box and get the value for each item.

but, i need to loop to x number and then do some thing else then start where i left off

but I cant "read the value" as I loop.

dim snval as string

For i = 0 To SCNCNT -1

snval = listbox1.index

Next

Ljhopkins  Wednesday, October 01, 2008 3:58 PM
For i As Integer = 0 To listbox1.Items.Count - 1
snval = listBox1.Items(i).ToString()
Next

nobugz  Wednesday, October 01, 2008 4:25 PM

Hi

If you want to get value from ListBox's item then you can write following statement.

Code Snippet

ListView1.Items.Item(INDEX).Text

If you want to do some task on particular item then you can do following code.

Code Snippet

For i As Integer = 0 To ListView1.Items.Count - 1

If ListView1.Items.Item(i).Text = "Your Condition" Then

Application.DoEvents()

End If

Next

Here you can replace your code at Application.DoEvents.

And after finishing your task loop will continue from next element of ListBox1.

If your requirement is different, or if i don't underestand your que properly, or if i am wrongthen let me know.

Thank You.

Best Regards,

Utakrsh Gajjar

Utkarsh  Wednesday, October 01, 2008 4:41 PM
For i As Integer = 0 To listbox1.Items.Count - 1
snval = listBox1.Items(i).ToString()
Next

nobugz  Wednesday, October 01, 2008 4:25 PM

Hi

If you want to get value from ListBox's item then you can write following statement.

Code Snippet

ListView1.Items.Item(INDEX).Text

If you want to do some task on particular item then you can do following code.

Code Snippet

For i As Integer = 0 To ListView1.Items.Count - 1

If ListView1.Items.Item(i).Text = "Your Condition" Then

Application.DoEvents()

End If

Next

Here you can replace your code at Application.DoEvents.

And after finishing your task loop will continue from next element of ListBox1.

If your requirement is different, or if i don't underestand your que properly, or if i am wrongthen let me know.

Thank You.

Best Regards,

Utakrsh Gajjar

Utkarsh  Wednesday, October 01, 2008 4:41 PM

You can use google to search for other answers

Custom Search

More Threads

• ToolTip control invokes parent OnMouseMove
• Drawing lines in windows forms
• Form draw speed
• How to change window type
• Gradient along a path
• Security Update for Microsoft .NET Framework, Version 2.0 (KB928365)
• Send A form window to another terminal
• WebBrowser Control & HTTP Response
• How to autosize
• stringBuilder in windows application