Io.FileInfo and comboBox control

R

R. Harris

Here is what I'm trying to accomplish:

When my form loads it looks at a specific directory for a list of its files
and populates a combo box.
Dim a As New IO.DirectoryInfo("c:\dir")
Dim b As IO.FileInfo() = a.GetFiles()
Dim c As IO.FileInfo

For Each c In b
comboBox1.Items.Add(c)
Next

And that works fine. Then I want to be able to use the entries in the combo
box as string variables to use to open a file for input. The problem is that
the above code populates the combobox with object references(?) so the
comboBox2.SelectedItems doesn't work because the .selectedItems is looking
for a string value. I guess what I'm trying to ask is how can I reference
the items in my combobox as strings so I can assign them to string
variables?

I hope my question isn't confusing because I know I am.
 
T

Tom Shelton

R. Harris said:
Here is what I'm trying to accomplish:

When my form loads it looks at a specific directory for a list of its files
and populates a combo box.
Dim a As New IO.DirectoryInfo("c:\dir")
Dim b As IO.FileInfo() = a.GetFiles()
Dim c As IO.FileInfo

For Each c In b
comboBox1.Items.Add(c)
Next

If I understand what your after then...

Dim files() as string = System.IO.Directory.GetFiles ("c:\dir")
For Each file As String in files
comboBox1.Items.Add (file)
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top