VS 2010 [RESOLVED] List of file names in combobox-VBForums
Results 1 to 9 of 9

Thread: [RESOLVED] List of file names in combobox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Buckingham, England
    Posts
    183

    Resolved [RESOLVED] List of file names in combobox

    I am trying to populate a combobox with a list of filenames from a selected directory. I am getting the directory OK but the combobox instead of having a list of 8 files max shown when I select the combobox has a full list of all the files selected from that directory.

    Code:
        Private Sub BrowseButton_Click(sender As System.Object, e As System.EventArgs) Handles BrowseButton.Click
            If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
                TextBox1.Text = FolderBrowserDialog1.SelectedPath
            End If
            Dim BackupFolder As String = TextBox1.Text
            For Each BackupFiles As String In My.Computer.FileSystem.GetFiles(BackupFolder, FileIO.SearchOption.SearchTopLevelOnly, "PigginGifts*.bak")
                ComboBox1.Items.Add(IO.Path.GetFileName(BackupFiles))
            Next
        End Sub

  2. #2
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    448

    Re: List of file names in combobox

    what makes you think there's only 8 files in the folder? the way you have it set up now, your are populating the combo with all the files in that folder. if there are more then 8 files, it will still be added. so, you can limit the number of files in the folder or limit what files should be added
    if i was able to help, rate my post!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Buckingham, England
    Posts
    183

    Re: List of file names in combobox

    I agree there are more than 8 files in the folder and I am displaying them all but I have the the max download files set to 8 so I wanted the first 8 to show and then be able to scroll through the rest if required. Normally the first one will be the required one.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Buckingham, England
    Posts
    183

    Re: List of file names in combobox

    sorry max dropdown files set to 8.

  5. #5
    vb Coda .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    19,099

    Re: List of file names in combobox

    try this:

    vb Code:
    1. Private Sub BrowseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseButton.Click
    2.     If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
    3.         TextBox1.Text = FolderBrowserDialog1.SelectedPath
    4.         Dim BackupFolder As String = TextBox1.Text
    5.         For Each BackupFiles As String In My.Computer.FileSystem.GetFiles(BackupFolder, FileIO.SearchOption.SearchTopLevelOnly, "PigginGifts*.bak").Take(8).ToArray
    6.             ComboBox1.Items.Add(IO.Path.GetFileName(BackupFiles))
    7.         Next
    8.     End If
    9.        
    10. End Sub

  6. #6
    Hyperactive Member jasonwucinski's Avatar
    Join Date
    Mar 2010
    Location
    Pittsburgh
    Posts
    448

    Re: List of file names in combobox

    i see what you are saying. there are a couple of ways to do this. the easiest might be create a list collection of all files like this:

    Code:
            Dim myFileList As New List(Of String)
    then fill the list like this:

    Code:
    For Each BackupFiles As String In My.Computer.FileSystem.GetFiles(BackupFolder, FileIO.SearchOption.SearchTopLevelOnly, "PigginGifts*.bak")
            
    
         myFIleList.add(IO.Path.GetFileName(BackupFiles))\
    
            Next
    Now you have a collection of all files. You can iterate of this list any way you want (8 items at a time, for instance). So, you can have a variable like CurrentCount = 0. Each time a user hits a "next set" button or label, increment the count by 8. then you can use a for loop. (ie for i = CurrentCount to myFIleList.length)
    if i was able to help, rate my post!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Buckingham, England
    Posts
    183

    Re: List of file names in combobox

    I am not trying to display the files in blocks of 8 but rather like other comboboxes I have used to display files from records where if there are more than 8 items selected then the dropdown box below the combobox has a scroll bar to display the other selected items.

  8. #8
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    5,810

    Re: List of file names in combobox

    The following is a simulation to show how to set MaxDropDownItems property of the ComboBox without worrying about how to populate the ComboBox.

    In the code below I would be in trouble as when the DropDown was open it would extend pass my client area of my display screen. So this means you may or may not have to adjust MaxDropDownItems.

    Code:
    Private Sub demo()
        Dim rand As Random = New Random()
    
        ComboBox1.DataSource = Enumerable.Range(0, 100).Select(Function(i) _
            (Chr(Asc("A") + rand.Next(0, 26)))).ToList()
    
        ComboBox1.MaxDropDownItems = ComboBox1.Items.Count - 1
    End Sub

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Buckingham, England
    Posts
    183

    Re: List of file names in combobox

    I have now resolved my problem by setting the combobox1 dropdownheight to a value i.e.100 Setting the maxdropdownitems had noeffect at all and what I don't understand is why the dropdownheight had no effect till I set a new value. the default of 106 had no effect but if I typed in 106 then it did.
    Is this a bug?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.