Browse for folder from PropertyGrid

RussGreen77

Newcomer
Joined
Apr 30, 2005
Messages
2
I'm using a property grid in my application but several of the properties I want the user to input are folder paths. How can I add a folderbrowser dialog to a grid control?

I've seen (and used) an example ofselecting a filename with the OpenFile dialog and tried to modify that. This is where I ended up but it's not working.

Any ideas?

Code:
Public Class FolderBrowserX
    Inherits FileNameEditor
    Private _InitialDirectory As String
    Protected Overloads Sub InitializeDialog(ByVal fbd As FolderBrowserDialog)
        With fbd
            .RootFolder = _InitialDirectory
        End With
    End Sub

    Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
        Dim filterAtt As FileDialogParametersAttribute = _
               context.PropertyDescriptor.Attributes(GetType(FileDialogParametersAttribute))

        _InitialDirectory = filterAtt.InitialDirectory

        Return UITypeEditorEditStyle.Modal
    End Function
End Class

<AttributeUsage(AttributeTargets.Property)> _
 Public Class FolderDialogParametersAttribute : Inherits Attribute
    Private _InitialDirectory As String

    Public ReadOnly Property InitialDirectory() As String
        Get
            Return _InitialDirectory
        End Get
    End Property

    Public Sub New(Optional ByVal InitialDirectory As String = "C:\")
        MyBase.New()
        _InitialDirectory = InitialDirectory
    End Sub
End Class
 
Fixed it

Silly typo

Code:
Public Class FolderBrowserX
    Inherits FolderNameEditor

    Private _RootFolder As String
    Protected Overloads Sub InitializeDialog(ByVal fbd As FolderBrowserDialog)
        With fbd
            .RootFolder = _RootFolder
        End With
    End Sub

    Public Overloads Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
        Dim filterAtt As FolderDialogParametersAttribute = _
               context.PropertyDescriptor.Attributes(GetType(FolderDialogParametersAttribute))

        _RootFolder = filterAtt.RootFolder

        Return UITypeEditorEditStyle.Modal
    End Function
End Class

<AttributeUsage(AttributeTargets.Property)> _
 Public Class FolderDialogParametersAttribute : Inherits Attribute
    Private _RootFolder As String

    Public ReadOnly Property RootFolder() As String
        Get
            Return _RootFolder
        End Get
    End Property

    Public Sub New(Optional ByVal RootFolder As String = "C:\")
        MyBase.New()
        _RootFolder = RootFolder
    End Sub
End Class
 
Back
Top