Replacements for DirListBox and/or FileListBox from Microsoft.VisualBasic.Compatibility

9.8k views Asked by At

I have a VB6 application that has been migrated to VB.net, and am trying to upgrade the framework version to 4.5 -- which complained that everything in Microsoft.VisualBasic.Compatibility dll was obsolete. I was able to replace everything except the FileListBox and DirListBox fairly easily -- tedious but I didn't have to create any new controls.

Is there a close replacement for these controls? Does anyone know if they have been opened sourced with the rest of the framework?

2

There are 2 answers

1
KMan On BEST ANSWER

You can use simple ListBox control and use My.Computer.FileSystem to make them as old DriveListBox, DirectoryListBox and FileListBox. You can use something like following

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    lstDriveList.DataSource = My.Computer.FileSystem.Drives
End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstDriveList.SelectedIndexChanged
    lstDirectoryList.DataSource = My.Computer.FileSystem.GetDirectories(lstDriveList.SelectedValue.ToString())
End Sub


Private Sub lstDirectoryList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstDirectoryList.SelectedIndexChanged
    lstFileList.DataSource = My.Computer.FileSystem.GetFiles(lstDirectoryList.SelectedValue.ToString())
End Sub

All the lst are just normal ListBoxes you can also use ListView control, similar way.

0
joehanna On

Unfortunately you will have to roll your own (just like @kman has kicked you off).

Some alternatives have been discussed in this MSDN forums discussion (Internet Archive link): VB.Net equivalent of VB6 code which are obsolete

Someone suggested going back to Framework 3.5 (if you are not using 4.5 features) to buy some time to write new controls.