Click here to Skip to main content
12,948,130 members (77,313 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Is there a way that a drop down menu can automaticly read all the text files in a specified folder and display them into the drop down menu?
Because now I'm actually programming the txt files one by one and coupling them one by one to the correct buttons.
But is there a way that the drop down menu can load them in automatic?
Posted 19-Feb-13 2:35am
V. 19-Feb-13 8:44am
What are you trying to achieve? You want a list of all the filenames in the drop down, or do you want the contents of these files in the dropdown. Please be as specific as possible.
Darthillian 19-Feb-13 8:45am
I want a list of all the filenames of the txt extention in the dropdown menu and when I click on one that it shows me the contents of that txt file in a textbox.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this

System.IO.DirectoryInfo x = new System.IO.DirectoryInfo("c:\\");
this.comboBox1.DataSource = x.GetFiles();
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

1. You can use the the FileInfo and DirectoryInfo classes to get the list of files (filtered on txt extension if you wish). 2. 2. With that array you can fill your drop down menu.
3. When you click the menu item, open that file with the selected filename with for example the StreamReader class.

This is assuming that you have set a rootfolder as config.

Hope this helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,703
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100