We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

Lets say you have a form designed that is being run by the installer class.In the form there is a browse button to open the FOLDER BROWSE dialog. If you just drag and drop a folderbrowser control and implement code to open the dialog using SHOWDIALOG method, a dialog will open up with no treeview for folder structure.
 
To resolve this issue implement the code to start a new thread with ApartmentState as STA (single-threaded ) and open the folder browser dialog using the thread.
[START CODE VB.NET]
 
    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        txtFilePath.Text = getFilePath()
    End Sub
 
    '   Function to create a new thread
    Public Function getFilePath() As String
        Try
            Dim pathname As String = Nothing
            Dim FolderDlgThread As System.Threading.Thread = New System.Threading.Thread(AddressOf getFilePathThread)
            FolderDlgThread.ApartmentState = Threading.ApartmentState.STA
            FolderDlgThread.Start()
            FolderDlgThread.Join()
            pathname = dlgFolder.SelectedPath
            Return pathname
        Catch err As Exception
            MsgBox(err.Message)
            Return Nothing
        End Try
    End Function
 
    <STAThread()> _
    Public Sub getFilePathThread()
        Try
            Dim pathname As String = Nothing
            dlgFolder.Site = Nothing ' dlgFolder is the folder browser control name
            Dim stat As DialogResult = dlgFolder.ShowDialog()   '  open the folder browser dialog
            If stat = DialogResult.OK Then
                pathname = dlgFolder.SelectedPath
            End If
        Catch err As Exception
            MsgBox(err.Message)
        End Try
    End Sub
 

[END CODE VB.NET]


Related Tags:

VB.NET

Author: Amrita Dash

top

VB.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login