|
-
Dec 5th, 2000, 03:03 PM
#1
Thread Starter
Fanatic Member
Ok if you have two combo boxes and you want one combo box to fill in the contents according to criteria in the other combo box, how would you do it? Example, I have a combo box that filles that fills the file names of files in a directory on the network. What I would like to do is setup multiple directories and place the names of those directories in a combo box, then when someone chooses one of the directories in that combo box (clicks on the down arrow and highlights one) the contents of that directory gets filled in the second combo box....Any suggestions?
-
Dec 5th, 2000, 03:09 PM
#2
Addicted Member
Code:
Private Sub cboBox1.Click()
Dim curDir as String
'Check something is selected
If cboBox1.ListIndex <> -1 Then
'Get the selected directory
curDir = cboBox1.List(cboBox1.ListIndex)
'Fill the second combo
fillBox2 curDir
End If
End Sub
Private Sub fillBox2(curDir as String)
'Clear any previous entries
cboBox2.Clear
'Code below is pseudo-code
For Each File in curDir
cboBox2.AddItem File.Name
Next File
End Sub
I think that should work in concept anyway you'll need to work out the specifics of the code, but it's not my job to do all the work for you is it Have a nice day.
Regards
Matt Brown
Hamilton, NZ
VB6 C++ in Visual Studio 6sp4
VB.net Beta 1
-
Dec 6th, 2000, 11:17 AM
#3
Thread Starter
Fanatic Member
OK This is what I have thus far:
********************************************************
Private Sub cboq_Click()
'Clear any previous entries
'cboQuery.Clear
mydir1 = Dir("G:\qf1\*.PDF")
mydir2 = Dir("G:\qf2\*.PDF")
mydir3 = Dir("G:\qf3\*.PDF")
mydir4 = Dir("G:\qf4\*.PDF")
'mydir = Dir("G:\qf1\*.PDF")
'loop through directory until there are no files left, this will update the
'combo box
If cboQ.Text = "QT1" Then
Do While mydir1 <> ""
Call cboQuery.AddItem(mydir1)
mydir1 = Dir
Loop
Else
Exit Sub
End If
If cboQ.Text = "QT2" Then
Do While mydir2 <> ""
Call cboQuery.AddItem(mydir2)
mydir2 = Dir
Loop
Else
Exit Sub
End If
If cboQ.Text = "QT3" Then
Do While mydir3 <> ""
Call cboQuery.AddItem(mydir3)
mydir3 = Dir
Loop
Else
Exit Sub
End If
If cboQ.Text = "QT4" Then
Do While mydir4 <> ""
Call cboQuery.AddItem(mydir4)
mydir4 = Dir
Loop
Else
Exit Sub
End If
End Sub
*********************************************************
It crashes on the line: mydirx = dir
Any ideas?
-
Dec 6th, 2000, 12:07 PM
#4
Thread Starter
Fanatic Member
-
Dec 6th, 2000, 03:32 PM
#5
Addicted Member
Your problem is not with the concept of updating the second combo box you are doing that correctly although you could remove the Call before each addItem line but it doesn't matter.
The problem is occuring when you are trying to get the lists of files. I don't know much about this but I know you can use the API enumFiles or something like that.
Also if you are just wanting to display a list of files in a directory why don't you use the file / directory display lists that come standard in VB?
Regards
Matt Brown
Hamilton, NZ
VB6 C++ in Visual Studio 6sp4
VB.net Beta 1
-
Dec 6th, 2000, 03:44 PM
#6
Thread Starter
Fanatic Member
What are the file directory display lists????
-
Dec 6th, 2000, 03:51 PM
#7
Addicted Member
In your standard control toolbox there are 3 controls
Drive List
Directory List
File List
Hover your mouse over each control in the toolbox until you find these ones.
You can hook them up to each other so that when you select a drive the Directory list automatically refreshes and when you select a Directory the file list automatically refreshes. I can't remember the actually properties of the controls to do it know but I remember it being easy.
There's got to be a tip or article for it on the site somewhere. Try doing a search for it.
Regards
Matt Brown
Hamilton, NZ
VB6 C++ in Visual Studio 6sp4
VB.net Beta 1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|