Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox Newindex, can i store 2 indexes?

Status
Not open for further replies.

mur3x

MIS
Sep 8, 2003
31
LK
Hi! i use a Listbox to populate Name field. So with that i want to store
the particular ID & Description attached to that name.

i tried,

Code:
Do While i < rs2.RecordCount
    lstModules.AddItem rs2(&quot;name&quot;)
    lstModules.ItemData(lstModules.NewIndex) = rs2.Fields(&quot;ID&quot;) 'stores realted ID
    i = i + 1
    rs2.MoveNext
Loop

The above code works fine as it stores only the 'ID' field.how can i do something
like below so that it wud store the 'desc' field too.

Code:
lstModules.ItemData(lstModules.NewIndex) = rs2.Fields(&quot;desc&quot;) 'stores related desc


suggestions much appreciated..


thnx!!
Mur.

 
Why? It is additional data not show to the user in the list box, so instead just use the item data to find the record in the recordset and get the additional info.
If you use a client side cursor you can disconnect the recordset from the source if this is a concern (Set rs.ActiveConnection = Nothing).
Then your recordset can hold mmany more fields.
Otherwise, because this is not easily possible with a listbox, you can use a ListView or DataGrid or HFlexGrid in order to display the data in a list similar to a listbox.

With a list box you could also use:
lstModules.AddItem rs2(&quot;name&quot;) & vbTab & vbTab & rs2.Fields(&quot;desc&quot;)

You can then use the Split(), or, Instr() Len() and Right() functions to retreive the second &quot;field&quot; values from the listbox.
but it will not line up correctly if some data in the first field in long and some short.

 
thnx for the tip!!! i was fed up with grids.
so i used Listview instead. great! i d'nt know
it has such better features.

Mur.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top