Io.FileInfo and comboBox control

  • Thread starter Thread starter R. Harris
  • Start date Start date
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.
 
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
 
Back
Top