-
Apr 10th, 2012, 02:24 PM
#1
Thread Starter
Addicted Member
[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
-
Apr 10th, 2012, 02:28 PM
#2
Hyperactive Member
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!
-
Apr 10th, 2012, 02:37 PM
#3
Thread Starter
Addicted Member
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.
-
Apr 10th, 2012, 02:38 PM
#4
Thread Starter
Addicted Member
Re: List of file names in combobox
sorry max dropdown files set to 8.
-
Apr 10th, 2012, 02:47 PM
#5
Re: List of file names in combobox
try this:
vb Code:
Private Sub BrowseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrowseButton.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
Dim BackupFolder As String = TextBox1.Text
For Each BackupFiles As String In My.Computer.FileSystem.GetFiles(BackupFolder, FileIO.SearchOption.SearchTopLevelOnly, "PigginGifts*.bak").Take(8).ToArray
ComboBox1.Items.Add(IO.Path.GetFileName(BackupFiles))
Next
End If
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 10th, 2012, 02:51 PM
#6
Hyperactive Member
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!
-
Apr 10th, 2012, 03:30 PM
#7
Thread Starter
Addicted Member
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.
-
Apr 10th, 2012, 05:12 PM
#8
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
-
Apr 11th, 2012, 05:36 AM
#9
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|