Groups | Blog | Home
all groups > vb.net controls > april 2005 >

vb.net controls : Listbox


Bob
4/13/2005 12:32:28 PM
Hello all:

I recently have converted from VB 6.0 to VB.NET. I was wondering if you can
tell me how to obtain the value of an item of a listbox without actually
selecting that item. For example, let's say that I have a listbox that
lists the 50 states of the US. Currently let's say item 10 is selected.
Now, how do I obtain the value of items 25, 30, 35 and 40?

I appreciate all your help.

Bob

Herfried K. Wagner [MVP]
4/13/2005 10:53:16 PM
"Bob" <anonymous@discussions.microsoft.com.invalid> schrieb:
[quoted text, click to view]


\\\
Dim s As String = DirectCast(Me.ListBox1.Items(25), String)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Herfried K. Wagner [MVP]
4/16/2005 12:00:00 AM
"Bob" <anonymous@discussions.microsoft.com.invalid> schrieb:
[quoted text, click to view]

Untested:

\\\
For i As Integer = 0 To Me.ListBox1.Items.Count - 1
MsgBox(DirectCast(Me.ListBox1.Items(i), String))
Next i
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Bob
4/16/2005 12:57:59 PM
Thanks Herfried for your suggestion. I still am not clear on how to use
this. Does it mean I have to use the Dim command for items 30, 35 and 40?
I am sure there has to be a property or method that gives me the values of
any item in the listbox. For example if I have to run a loop to obtain the
values, or something.

Thanks;

Bob

[quoted text, click to view]

AddThis Social Bookmark Button