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 :-)

Re: C# ComboBox help plz. by Bryan

Bryan
Fri Oct 27 17:06:34 CDT 2006

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




"A" <aerodynex@gmail.com> wrote in message
news:1161348682.287044.183290@m7g2000cwm.googlegroups.com:

> 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 :-)