Try doing something like this:
Public Sub New()
Dim directories As New List(Of DirectoryInfo)
Call Me.InitializeComponent()
Call Me.ComboBox1.Items.Clear()
For Each directory As DirectoryInfo In (New DirectoryInfo("C:\")).GetDirectories()
Call directories.Add(directory)
Me.ComboBox1.Items.Add(directory.Name)
Next
End Sub
This will generate a list directories
of DirectoryInfo
objects for all directories found in the specified path. It will also add all directory names to the combobox (in this case Combobox1
.
UPDATE
Just realised that you asked for an array specifically. You can transform a list to array by using the ToArray()
extension method. So in this case at the end of the sub you can just call directories.ToArray()
to get your array. Alternatively you can use the code I wrote with an array, but frankly, why use an array if you can use a list?
If you want to do it with an array here is the code:
Public Sub New()
Dim i as integer
Call Me.InitializeComponent()
ReDim directory(i)
For Each dir As DirectoryInfo In (New DirectoryInfo("C:\")).GetDirectories()
directory(i) = dir
Me.ComboBox1.Items.Add(directory.Name)
i += 1
ReDim Preserve directory(i)
Next
End Sub
But I think it's a pain in the backside to do it this way...