I am trying to figure out the way to list all the files from the folder in comboBox2 for every available folder
Any suggestions and help is appreciated?
ComboBox1: Lists all the folders from physical location.(Works fine)
ComboBox2 lists all files when folder from comboBox1 is selected.
As number of folders are not fixed, I am looking for some loop.
private void Marriage_Load(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(@"\\Phhistmsimgid02\CAMR");
paths = new String[di.GetDirectories().Count()];
// MessageBox.Show(paths.Length + "");
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.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo dinf = new DirectoryInfo(@"\\Phhistmsimgid02\CAMR\M07201400802");
paths = new String[dinf.GetFiles().Count()];
int i = 0;
comboBox2.Items.Clear();
pictureBox2.Image = Image.FromFile(@"\\Phhistmsimgid02\CAMR\M07201400802\SCN0001.tif");
foreach (FileInfo finf in dinf.GetFiles())
{
comboBox2.Items.Add(finf.Name);
var count = comboBox2.Items.Count;
//MessageBox.Show("Count is:" + count);
}
foreach (FileInfo finf in dinf.GetFiles())
{
paths[i] = finf.FullName;
i++;
}
} // this part works fine if I mention each folder manually.
Any suggestions and help appreciated.
Raghav JhavarPosted Dec 13, 2015, 1:47 AM
using System;
Result:
Pick a folder in comboBox1
All images ending with ".png" in the folder will be added to comboBox2.
After I select an image in comboBox2, picturebox image location will change to that picture and refresh, displaying the picture selected in comboBox2 :)