Merlin my friend, I know just how you feel.
The fastest way is to use the databinding stuff (*Yuk*):
------------------
'Get yer data:
sSQL = "SELECT FruitID, FruitName FROM Fruits"
ds = GetDataset(sSQL)
With ListBox
.DataSource = ds.Tables(0) 'only table in ds
.DisplayMember = "FruitName"
.ValueMember = "FruitID"
End with
ds.dispose()
------------------
Yes, that will actually populate it, keys and all!
If you try to be really economical and do it with a
datareader, well, sorry you can't bind the thing.
(disappointing, I know).
Anyway to get your key back out from the selected:
----------------------------------
Dim nSelectedKey as integer
nSelectedKey = ListBox.SelectedValue
--------------------------------------
Remember "SELECTED" is the point here. The Item must have
the highlight (selection).
Watch out for the *Checked*ListBox, that will really make
you angry!
Good luck
Doz
___.-~@~-.___
Dorian Hill.
Microsoft Certified Solution Developer
Momentech Software Services
PO Box 348, Caulfield East, VIC 3145, Australia
E-Mail:
do*********@hotmail.com -----Original Message-----
Been using VS NET for a while now but never really used
the Standard ListBoxcontrol until now and whoops! where's the ItemData method
gone - damn!,can't Microsoft leave things alone.
Anyway did a quick read up and found that Listbox is not
limited to stringsanymore and each item can contain an object bla bla
bla...Z Z z z z...
Can someone please put me out of my misery and just
quickly show me how toadd a string item and a value like in the VB6 version.
Been looking forexamples but can't actually find anything that actually
gets to the point.
All I want to do is add 20 text items with an associated
Long number(key).and when I select an item, to be able to also access the
(key).
Many Many thanks.
Merlin
.