Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox that lists files

Status
Not open for further replies.

speek

Technical User
Mar 29, 2008
25
US
I would like to make a combobox that lists all .exe files in the programs directory. Anyone has some source code for me that I could use for that? Thanks,

Speek
 
On the control toolbar, use DriveListBox and FileListBox. All properties and methods are already defined for you. To get an example, go to msdn.microsoft.com and type in drivelistbox
 
I use this code:



Dim MyFile as String

MyFile = Dir(App.Path & "\*.exe")

Do While MyFile <> &quot;&quot;

Combo1.AddItem MyFile
MyFile = (Dir)

Loop
 
Sacsac,

I tried your code and it works to some extend. The problem I still have is that I don't know under what Private Sub I should put your code.

If I put it under Private Sub Combo1_Change() then the combobox stays empty at runtime. Only when you type letters in the combo box there appears a list of exe files. When you type 1 letter the list is there as it should be. When you type 2 letters you get a double list. Etcetera.

When I put the code under Private Sub Combo1_DropDown() a new list of .exe files is added to the previous list every time you click the dropdown button of the combo box, so I get the same .exe files more than once in the combobox.

Do you have a solution?

Thanks for your help, it's much appreciated.

Speek
 
Speek

Sorry - I havn't been in the forum for a long time!

If you still have not resolved your problem, then I would recommend that you put the code in Form.Load. This will ensure that it is populated at the outset.
If you have the code in DropDown or Change, then you WILL get the repeated data as you describe (You could prevent this by having a Combo.Clear at the start of the Sub)

Hope this has helped


sacsac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top