Click here to Skip to main content
14,735,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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.
Nomardus 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.

Try this

System.IO.DirectoryInfo x = new System.IO.DirectoryInfo("c:\\");
this.comboBox1.DataSource = x.GetFiles();
   
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)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900