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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list box controls

Status
Not open for further replies.

phly9design

Programmer
May 11, 2001
1
US
i have 3 list boxes (manufacturers, models, and descriptions)

manufacturers is all set up with the list content, but how do i make it so that when a user clicks a manufacturer from the list the models list will show the models only for that manufacturer, and when they choose a model it will show the descriptions in the descriptions list box???

also how can i search a list box so that when i type in a manufacturer in one box it will take me automatically to that manufacturer and show me the models for it??

how can i search a list box so that when i type in a model in one box and click a buton it will take me automatically to that manufacturer, model, and description?

any ideas or solutions would help

phly
 
One way to solve this problem would be to add items to the following list boxes, depending on the selection of the manufacturer's list box.

this would look something like this:

Private Sub MftList_Click()
select case mftList.ListIndex
case 0
ModelList.AddItem "Man. 1 Model 1"
case 1
ModelList.Additem "Man. 2 Model 1"
end sub

then you can do the same procedure on the model list to populate the description list.

hopefully this will guide you in the right direction.
Best Regards and many Thanks!
Michael G. Bronner X-)

"Beer is proof that God wants us to be happy." Ben Franklin
 
I am assuming that you have the contents of all three list boxes in a database of some sort.

Once the user clicks the Manfactures listbox

Private sub lstManufacturers_click()
'----------------------------------------------'
'You can use the same logic for retrieving the '
'descriptions per model '
'----------------------------------------------'
dim Conn as New Adodb.Connection
dim rs as new Adodb.Recordset
dim sql_sel as string 'unless you have a stored query

'open the connection if not global
Conn.Open "...;...;...;...;"

'clear the models list so that only models for the
'selected manufacturer appear
lstModels.Clear

'Create a select statement to retrieve all models for
'the selected manufacturer, if no Parameter query exists
'in the database
sql_sel = "Select Models from tblModel where Manufacturer = " & lstManufacturers.list(lstManufacturers.listindex)

'open a recordset object retrieving the models
set rs = conn.execute(sql_sel)

'check that model records were returned
if not rs.eof and not rs.bof then

'place models into an array
ar = rs.getrows

'loop through array placing models into the models
'list box
for x = lbound(ar,2) to ubound(ar,2)
lstModels.additem ar(0,x)
next x
else
'if no models returned post message in list box
lstModels.additem "No Models for this manufacturer"
end if
end sub


'----------------------------------------------------------------------------------------------------------------------------------------

For the next item
Simply move through the list box using the left$() function to test each item in the list and exit when you find the first that matches
Private sub txtSearch_keypress(Ascii as integer)

if len(txtSearch.text) > 0 then
for x = 0 to lstManufacturers.listcount -1
if left$(lstManufacturers.list(x),len(txtSearch.text) = txtSearch.text then
lstManufacturers.listindex = x
exit for
end if
next x
end if

end sub


Please excuse any spelling mistakes, as I did not write
this in Visual Basic first. I just typed in into this
text area from memory.

Good luck,
From: Gary A. Jackson (Programmer and Web Developer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top