CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: combobox

  1. #1
    Join Date
    May 2001
    Posts
    34

    combobox

    As part of a program I am writing i need to be able to have a combobox fill with a list of files in a directory. so they can be selected and then processed.

    can anyone please help?



    -DAVE

  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: combobox

    Use an invisible file list box. It will list for you all files in a directory. Then write a loop that will add all items of this file list box to the combo box.




  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: combobox

    look at this:
    'one command button, one combobox (named "cboCombo")
    Option Explicit

    'original code from Kamilche

    Private Sub FileList(ByVal Pathname As String, Optional DirCount As Long, Optional FileCount As Long)
    'at this directory level and lower.
    'Example of usage:
    'RichTextBox1.Text = FileList("c:\window
    ' s")
    Dim ShortName As String, LongName As String
    Dim NextDir As String
    Static FolderList As Collection
    Screen.MousePointer = vbHourglass
    'First time through only, create collect
    ' ion
    'to hold folders waiting to be processed
    ' .


    If FolderList Is Nothing Then
    Set FolderList = New Collection
    FolderList.Add Pathname
    DirCount = 0
    FileCount = 0
    End If


    Do
    'Obtain next directory from list
    NextDir = FolderList.Item(1)
    'Remove next directory from list
    FolderList.Remove 1
    'List files in directory
    ShortName = Dir(NextDir & "\*.*", vbNormal Or _
    vbArchive Or _
    vbDirectory)


    Do While ShortName > ""


    If ShortName = "." Or ShortName = ".." Then
    'skip it
    Else
    'process it
    LongName = NextDir & "\" & ShortName


    If (GetAttr(LongName) And vbDirectory) > 0 Then
    'it's a directory - add it to the list o
    ' f directories to process
    FolderList.Add LongName
    DirCount = DirCount + 1
    Else
    'it's a file - add it to the list of fil
    ' es.
    cboCombo.AddItem LongName

    FileCount = FileCount + 1
    End If
    End If
    ShortName = Dir()
    Loop
    Loop Until FolderList.Count = 0
    Screen.MousePointer = vbNormal
    End Sub
    Private Sub Command1_Click()
    Call FileList("c:")
    End Sub


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured