Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 C# C#4.0
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
Comments
V. at 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 at 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
good
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();
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 585
1 mhegazy94 460
2 Ravi Bhavnani 230
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,295
1 OriginalGriff 6,841
2 CPallini 5,420
3 George Jonsson 3,654
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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