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

Listbox in VB6

Status
Not open for further replies.

acjeff

Programmer
Aug 10, 2004
148
US
Hi,

I have a couple of filtering listbox in a form. Can I set each data in a listbox with name or names?

For example, a listbox for company name, a listbox for customer name, and a listbox for contract number. When selecting a company, corresponding customer name and contract number will be shown. When selecting another customer, data will be changed again in other listboxes. All data will be shown when not selecting any data.

However, I don't want to requery the database everytime a data is selected because it will slow down the application. If I have a data name for customer listbox identifying what company it belongs to, and 2 data names for contract number identifying what company and customer it belongs to. Can I do that in VB6?

Jeff
 
You can store all the data in arrays, I'm thinking UDT's, with 'linking' fields. Then you just need to loop through the arrays and only load the relevant data into the list boxes.

zemp
 
Use the Listbox.itemdata property to store unique values, Such as companyID, that you may need to access later. mainly because your .listindex property probably won't help you determine which array element corresponds to your selected item.

zemp
 
acjeff,

This can get pretty tricky if all list boxes are visible at the same time. Consider placing the lists on separate tabs of a tab control and only updating the lists (filtered by the selections made in the other two lists) as they become visible.
You can record the filter settings made in a text box below the tab control so that eg. You know the Company name which has been previously set when viewing the Customer tab/ list.

regards hugh
 
Jeff,

yes you can. You dont have to requery because you recodsets are already populated with the data. Just reuse the populated recordset.
To capture the listbox name us a "Click event" sub
It will pass the line item you cliked on to a variable you assign.

Then us it to search through you already populated record set.

Private Sub List1_Click()
Dim Item_Clicked_on As String

Item_Clicked_on = List1.Text
Pass the var to you sub or wherever your recordset is.
'You can also make the var Item_Clicked_on a global
End Sub

The just say

With MyRS
.movefirst
end with

While not MyRS.eof

Pull your data here

MyRs.movenext
wend



Hope this makes sense


Dan
 
hya, acjeff
it sounds like you are designing the same application as my self. i am too trying to acheive the same outcome using listboxes for the same purposes.
i would like a listbox with a list of company names, then on selecting a company name the user is asked to select a department within that company, then the Area(Area of the country they work for) on doing this a list of employee names will appear with their contact number.

i am interested how you are going to acheive this?
i am new to vb6 as my exerience lies with access,
 
>>I don't want to requery the database everytime a data is selected because it will slow down the application

How much data are you returning? I don't think that doing this should slow down your application unless you're returning hundreds of records for each. In which case, storing and keeping all of them in memory is not something I would do either. If your tables are indexed properly then "chaining" list boxes should not slow down the application - unless, of course, there are other undisclosed outside factors.

Another question to ask is when does the application go back and get new information? What happens when the data is updated by another process? Will you just have the user working with old data?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top