I am working on windows application. I am using 2 comboboxes, where first comboBox1 lists all the folders in the physical directory and comboBox2 lists all the files from the folders listed in comboBox1, when particular folder name is selected from comboBox1.
I am trying to figure out the way to list all the files from the folder in comboBox2 for every available folder and check count of files within the folder and when files in the folder reached end of file, selected index should move to next folder in the comboBox1.
As folder don't have same number of files in each folder I am trying something like recursion.
Any suggestions and help is appreciated?
ComboBox1: Lists all the folders from physical location.(Works fine)
private void Form_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("@\\server\CAMR");
paths = new String[di.GetDirectories().Count()];
int i = 0;
foreach (DirectoryInfo fi in di.GetDirectories())
{
comboBox1.Items.Add(fi.Name);
}
foreach (DirectoryInfo fi in di.GetDirectories())
{
paths[i] = fi.FullName;
i++;
comboBox2.Sorted = true;
}
comboBox1.Text = "";
}
ComboBox2: As of now I am doing it manually for each selected index from comboBox1
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 1)
{
DirectoryInfo dinf = new DirectoryInfo(@"\\server\CAMR\Mxxxxxxxxxxx");
paths = new String[dinf.GetFiles().Count()];
int i = 0;
comboBox2.Items.Clear();
pictureBox2.Image = Image.FromFile("@\\server\CAMR\Mxxxxxxxxxxx\SCN0001.tif");
foreach (FileInfo finf in dinf.GetFiles())
{
comboBox2.Items.Add(finf.Name);
}
foreach (FileInfo finf in dinf.GetFiles())
{
paths[i] = finf.FullName;
i++;
}
comboBox2.Text = "SCN0001.tif";
txtovrbn.Text = comboBox1.Text;
txtovrts.Text = DateTime.Now.ToString();
}
}
I am trying to find recursion here, so it will take care of all the folder listed in comboBox1.