Folder Browser Dialog Component not showing folders list in windows forms

1.5k Views Asked by At

I have a C# library containing form in which i am using Folder Browser Dialog Component to get the folder path. Form is shown during installation of my application using Custom Installer. When click on browse button to show folder browser dialog. Dialog opened but there was no folder list, blank dialog is shown with OK and Cancel button. I am using the below code:

FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
    txtDBPath.Text = folderBrowserDialog.SelectedPath; 
    btnSelectFile.Enabled = true;
}

How can i solve this issue. thanks

1

There are 1 best solutions below

0
On

I solved this problem.

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Try
        Dim MyThread As New Threading.Thread(AddressOf ShowMyFolderBrowserDialog)
        MyThread.SetApartmentState(Threading.ApartmentState.STA)
        MyThread.Start()
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Setup")
    End Try
End Sub

Private Sub ShowMyFolderBrowserDialog()
    Try
        Me.FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
        Me.FolderBrowserDialog1.Description = "Select folder"
        If System.IO.Directory.Exists(Me.TextBox1.Text) Then
            Me.FolderBrowserDialog1.SelectedPath = Me.TextBox1.Text
        End If
        If Me.FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.TextBox1.Text = Me.FolderBrowserDialog1.SelectedPath
        End If
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Setup")
    End Try
End Sub