Results 1 to 7 of 7

Thread: Combo BOx stuff

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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?

  2. #2
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Anyone??????

  5. #5
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    What are the file directory display lists????

  7. #7
    Addicted Member
    Join Date
    Aug 1999
    Location
    Hamilton, New Zealand
    Posts
    137
    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
  •  



Click Here to Expand Forum to Full Width