Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 

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

Posted

Fixed it

 

Silly typo

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...