weirddemon
asked on
Loop Through FileInfo objects in a ComboBox
I am adding files to a ComboBox like so:
For Each fReports As FileInfo In dirReports.GetFiles
tscboxReports.Items.Add(fR eports)
Next
I need to be able to list the contents of the appropriate file when the user selects an item. The listing part I already have figured out. What I need to know is how to loop through the items and then commit then action on that file.
I tried this:
For Each item As FileInfo In tscboxReports.SelectedItem
'Do Work
Next
I also tried it as an Object, but it still did not work.
This is the error I've received:
Unable to cast object of type 'System.IO.FileInfo' to type 'System.Collections.IEnume rable'.
The error is the same no matter if I loop through them as 'Objects' or 'FileInfos'.
Thanks
For Each fReports As FileInfo In dirReports.GetFiles
tscboxReports.Items.Add(fR
Next
I need to be able to list the contents of the appropriate file when the user selects an item. The listing part I already have figured out. What I need to know is how to loop through the items and then commit then action on that file.
I tried this:
For Each item As FileInfo In tscboxReports.SelectedItem
'Do Work
Next
I also tried it as an Object, but it still did not work.
This is the error I've received:
Unable to cast object of type 'System.IO.FileInfo' to type 'System.Collections.IEnume
The error is the same no matter if I loop through them as 'Objects' or 'FileInfos'.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ComboBox1.SelectedItem is not a collection of object hence can not be used in ( for in loop)
Selected item in a combo box will only have a single item. You'll either need to enumerate across the Items collection, or use a multi-select ListBox.
ASKER
Thanks