troubleshooting Question

Loop Through FileInfo objects in a ComboBox

Avatar of weirddemon
weirddemon asked on
Visual Basic Classic.NET ProgrammingVisual Basic.NET
4 Comments1 Solution641 ViewsLast Modified:
I am adding files to a ComboBox like so:

For Each fReports As FileInfo In dirReports.GetFiles
        tscboxReports.Items.Add(fReports)
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.IEnumerable'.

The error is the same no matter if I loop through them as 'Objects' or 'FileInfos'.

Thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros