MP S

MP S

  • NA
  • 1
  • 856

ComboBox selection from other comboBox input.

Nov 19 2015 4:22 PM
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(images) from the folders listed in comboBox1, when particular folder name is selected from comboBox1 to be displyed in pictureBox.

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. 

Answers (1)