From the code, I assume this is the line causing the exception:
DirectoryInfo dinfo01 = (di)ComboBox1mboBox1.SelectedItemtem;
The exception is clear. You are trying to convert SelectedItem, which is a string in your case into DirectoryInfo, which is not possible.
The SelectedItem will be a string, because you are binding
dinf.Name
to comboBox1
comboBox1.Items.Add(dinf.Name);
and you can convert it back to a string.
One solution will be to:
1) Get the directory name using SelectedItem
2) Use a foreach or LINQ to find the DirectoryInfo based on the name from Step 1
3) Find the file info of directory from step 2 and populate comboBox2.
Code may look something like this:
string dinfo01 = ComboBox1mboBox1.SelectedItemtem.ToString();
DirectoryInfo di = new DirectoryInfo("C:/Project");
foreach (DirectoryInfo dinf in di.GetDirectories())
{
if(dinf.Name.Equals(dinfo01))
{
foreach (FileInfo fi dinf.GetDirectories())
comboBox2.Item.Add(fi);
}
}
Note: This is just a sample code to give you an idea and it is not tested.
Hope this helps :)