C# ComboBox help plz.

  • Thread starter Thread starter A
  • Start date Start date
A

A

Hi all,

How do I get C# to populate a ComboBox with files from a folder?
They'll then be displayed into a DataGridView, but I think I got that
under control.

Another Q... if I wanted to make the ComboBox display the files in sub
selections like this:

Arts.resx
Arts.01.resx
Arts.02.resx
Movies.resx
Movies.ab.resx
Movies.cd.resx

Not in alphabetical order but just match similar names? Any help
thanks.


Much appreciated :-)
 
A simple way is to bind the ComboBox to an array:

comboBox1.DataSource = System.IO.Directory.GetFiles("C:\\temp");

To create your hierarchy do something like this:

ArrayList fileList = new ArrayList();
fileList.AddRange(System.IO.Directory.GetFiles("C:\\temp"));
fileList.Sort();

foreach(string fileName in fileList)
{
// Now you add some code to add each of the files to the combobox with
the right amount of indentation.
}



Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
 
Back
Top