Help grabbing info from a Listbox

DJB

New member
Joined
Feb 19, 2011
Messages
4
Programming Experience
Beginner
Hello.

I've made a listbox and imported multiple paths into it (writing the app in VB.NET 2.0).

For example:

C:\Path1\file1.txt
C:\Path2\file2.txt
C:\Path3\file3.txt (varies depending on what the user selects)

I need to be able to grab each path seperately without having to get the user to select a particular item so I can do a batch of all the paths selected.

Thanks in advance.
 
If you want the last item selected you use the SelectedItem property. If the user can select multiple items then you use the SelectedItems property, which is a collection, so you can loop through it. If you want all items then you use the Items property, which is also a collection.
 
Yes I'd want to use all the items. If possible could you please provide some sample code on how to do it.
 
If you don;t know how to write a simple loop then I suggest that you find yourself a good beginners tutorial and work through it. Loops are one of the fundamental building blocks of programming so any decent tutorial will cover them very early on. Here's one good option:

Microsoft Visual Basic .NET tutorials for Beginners

As you can see, loops are in lesson 4.
 
OK I've worked out the loop and how to get the amount of paths, but what is the line to select the listbox item within the loop

So far I have this:

Dim FileAmount As String = FileList.Items.Count
Dim i As Integer
For i = 1 To FileAmount
FilePath = ???? (this is where I need the code for the listbox line)

.....

Next i
 
There are several different types of loops available and each one is best suited to a certain type of situation. When you want to loop through a collection and use each item inside the loop, the most appropriate choice is a For Each loop.
 
Back
Top