as it is, i'd prefer not to spend hours looking for an upper / lower case letter thats out of place
and you're right... changing the functions / subs to shared didn't make a difference, in fact it didn't work at all... you can't use shared with overrides and/or mybase which are in the class (see below... class copied from the codeproject)
code (in its entirity):
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Design
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms
#Region " File dialogs"
Public Class OpenFileEditor
'
http://www.codeproject.com/vb/net/UIFilenameEditor.asp Inherits System.Drawing.Design.UITypeEditor
Public Overloads Overrides Function GetEditStyle(ByVal context As _
ITypeDescriptorContext) As UITypeEditorEditStyle
If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
Return UITypeEditorEditStyle.Modal
End If
Return UITypeEditorEditStyle.None
End Function
<RefreshProperties(RefreshProperties.All)> _
Public Overloads Overrides Function EditValue( _
ByVal context As ITypeDescriptorContext, _
ByVal provider As System.IServiceProvider, _
ByVal value As [Object]) As [Object]
If context Is Nothing OrElse provider Is Nothing _
OrElse context.Instance Is Nothing Then
Return MyBase.EditValue(provider, value)
End If
Dim fileDlg As FileDialog
fileDlg = New OpenFileDialog
fileDlg.Title = "Select " & context.PropertyDescriptor.DisplayName
fileDlg.FileName = value
Dim filterAtt As FileDialogFilterAttribute = _
context.PropertyDescriptor.Attributes(GetType(FileDialogFilterAttribute))
If Not filterAtt Is Nothing Then fileDlg.Filter = filterAtt.Filter
If fileDlg.ShowDialog() = DialogResult.OK Then
value = fileDlg.FileName
End If
fileDlg.Dispose()
Return value
End Function
End Class
Public Class SaveFileEditor
'
http://www.codeproject.com/vb/net/UIFilenameEditor.asp Inherits System.Drawing.Design.UITypeEditor
Public Overloads Overrides Function GetEditStyle(ByVal context As _
ITypeDescriptorContext) As UITypeEditorEditStyle
If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
Return UITypeEditorEditStyle.Modal
End If
Return UITypeEditorEditStyle.None
End Function
<RefreshProperties(RefreshProperties.All)> _
Public Overloads Overrides Function EditValue( _
ByVal context As ITypeDescriptorContext, _
ByVal provider As System.IServiceProvider, _
ByVal value As [Object]) As [Object]
If context Is Nothing OrElse provider Is Nothing _
OrElse context.Instance Is Nothing Then
Return MyBase.EditValue(provider, value)
End If
Dim fileDlg As FileDialog
fileDlg = New SaveFileDialog
fileDlg.Title = "Select " & context.PropertyDescriptor.DisplayName
fileDlg.FileName = value
Dim filterAtt As FileDialogFilterAttribute = _
context.PropertyDescriptor.Attributes(GetType(FileDialogFilterAttribute))
If Not filterAtt Is Nothing Then fileDlg.Filter = filterAtt.Filter
If fileDlg.ShowDialog() = DialogResult.OK Then
value = fileDlg.FileName
End If
fileDlg.Dispose()
Return value
End Function
End Class
<AttributeUsage(AttributeTargets.Property)> _
Public Class FileDialogFilterAttribute
Inherits Attribute
Private m_filter As String
''' <summary>
''' The filter to use in the file dialog in UIFilenameEditor.
''' </summary>
''' <value></value>
''' <remarks>The following is an example of a filter string: "Text files (*.txt)|*.txt|All files (*.*)|*.*"
''' </remarks>
''' <history>
''' [Vadim] 30/12/2003 Created
''' </history>
Public ReadOnly Property Filter() As String
Get
Return Me.m_filter
End Get
End Property
''' <summary>
''' Define a filter for the FileNameEditor.
''' </summary>
''' <param name="filter">The filter to use in the file dialog in FileNameEditor. The following is an example of a filter string: "Text files (*.txt)|*.txt|All files (*.*)|*.*"</param>
''' <remarks></remarks>
''' <history>
''' [Vadim] 30/12/2003 Created
''' </history>
Public Sub New(ByVal filter As String)
MyBase.New()
Me.m_filter = filter
End Sub
End Class
'Public Class FolderBrowserEditor
' Inherits System.Drawing.Design.UITypeEditor
' 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
#End Region
#Region " DropDown "
Public Class DropDownBoxEditor
'
http://www.codeproject.com/vb/net/UniversalDropdownEditor.asp Inherits UITypeEditor
Private edSvc As Windows.Forms.Design.IWindowsFormsEditorService
Private valMemb As ValueMemberAttribute
Public Overloads Overrides Function GetEditStyle(ByVal context As _
ITypeDescriptorContext) As UITypeEditorEditStyle
If Not context Is Nothing AndAlso Not context.Instance Is Nothing Then
Return UITypeEditorEditStyle.DropDown
End If
Return UITypeEditorEditStyle.None
End Function
<RefreshProperties(RefreshProperties.All)> _
Public Overloads Overrides Function EditValue( _
ByVal context As ITypeDescriptorContext, _
ByVal provider As System.IServiceProvider, _
ByVal value As [Object]) As [Object]
If context Is Nothing OrElse provider Is Nothing _
OrElse context.Instance Is Nothing Then
Return MyBase.EditValue(provider, value)
End If
Dim att As SourceCollectionAttribute = _
context.PropertyDescriptor.Attributes( _
GetType(SourceCollectionAttribute))
If att Is Nothing Then
' nothing we can do here
Return MyBase.EditValue(provider, value)
End If
Me.edSvc = provider.GetService(GetType(Windows.Forms.Design.IWindowsFormsEditorService))
If Me.edSvc Is Nothing Then
' nothing we can do here either
Return MyBase.EditValue(provider, value)
End If
' prepare the listbox
Dim lst As New ListBox
Me.PrepareListBox(lst, att, context)
If Me.valMemb Is Nothing Then
lst.SelectedItem = value
Else
Me.valMemb.SelectByValue(lst, value)
End If
Me.edSvc.DropDownControl(lst)
' we're back
If lst.SelectedItem Is Nothing Then
value = Nothing
ElseIf Me.valMemb Is Nothing Then
value = lst.SelectedItem
Else
value = Me.valMemb.GetValue(lst.SelectedItem)
End If
Return value
End Function
Private Sub PrepareListBox(ByVal lst As ListBox, _
ByVal att As SourceCollectionAttribute, _
ByVal context As ITypeDescriptorContext)
lst.IntegralHeight = True ' resize to avoid partial items
Dim coll As ICollection = att.Collection(context.Instance)
If lst.ItemHeight > 0 Then
If Not coll Is Nothing AndAlso _
lst.Height / lst.ItemHeight < coll.Count Then
' try to keep the listbox small but sufficient
Dim adjHei As Integer = coll.Count * lst.ItemHeight
If adjHei > 200 Then adjHei = 200
lst.Height = adjHei
End If
Else ' safeguard, although it shouldn't happen
lst.Height = 200
End If
lst.Sorted = True ' present in alphabetical order
FillListBoxFromCollection(lst, coll)
Me.AssignValueMember(lst, context.PropertyDescriptor)
Me.AssignDisplayMember(lst, context.PropertyDescriptor)
' attach event handler
AddHandler lst.SelectedIndexChanged, AddressOf Me.handleSelection
End Sub
Public Shared Sub FillListBoxFromCollection(ByVal lb As ListBox, ByVal coll As ICollection)
' prevent flickers and slow downs by entering the mass update mode
lb.BeginUpdate()
lb.Items.Clear()
Dim item As Object
For Each item In coll
lb.Items.Add(item)
Next
lb.EndUpdate()
lb.Invalidate()
End Sub
Private Sub AssignValueMember(ByVal lc As ListControl, ByVal pd As PropertyDescriptor)
Me.valMemb = pd.Attributes(GetType(ValueMemberAttribute))
If Me.valMemb Is Nothing Then Return
' maybe one day it'll work by itself...
lc.ValueMember = Me.valMemb.ValuePropertyName
End Sub
Private Sub AssignDisplayMember(ByVal lc As ListControl, ByVal pd As PropertyDescriptor)
Dim att As DisplayMemberAttribute = pd.Attributes( _
GetType(DisplayMemberAttribute))
If att Is Nothing Then Return
lc.DisplayMember = att.DisplayPropertyName
End Sub
Private Sub handleSelection(ByVal sender As Object, ByVal e As EventArgs)
If Me.edSvc Is Nothing Then Return
Me.edSvc.CloseDropDown()
End Sub
End Class
''' <summary>
''' Service attribute to point to the source collection.
''' </summary>
''' <remarks></remarks>
''' <history>
''' [afiq] 25/12/2003 Created
''' </history>
<Description("Service attribute to point to the source collection."), _
AttributeUsage(AttributeTargets.All)> _
Public Class SourceCollectionAttribute
Inherits Attribute
Private srcCollName As String
Public ReadOnly Property CollectionName() As String
Get
Return Me.srcCollName
End Get
End Property
Public ReadOnly Property Collection(ByVal instance As Object) As ICollection
Get
Dim pdc As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(instance)
Dim pd As PropertyDescriptor
For Each pd In pdc
If pd.Name = Me.srcCollName Then
Return pd.GetValue(instance)
End If
Next
Return Nothing
End Get
End Property
Public Sub New(ByVal sourceCollectionPropertyName As String)
Me.srcCollName = sourceCollectionPropertyName
End Sub
End Class
''' <summary>
''' Specifies the member returning value in the list control used by the dynamic combo editor.
''' </summary>
''' <remarks></remarks>
''' <history>
''' [afiq] 05/02/2004 Created
''' </history>
<AttributeUsage(AttributeTargets.All)> _
Public Class ValueMemberAttribute
Inherits Attribute
Private valMemb As String
''' <summary>
''' Gets the name of the property used as value member by the dynamic combo type editor.
''' </summary>
''' <value></value>
''' <remarks></remarks>
''' <history>
''' [afiq] 05/02/2004 Created
''' </history>
<Description("The name of the property used as value member by the dynamic combo type editor.")> _
Public ReadOnly Property ValuePropertyName() As String
Get
Return Me.valMemb
End Get
End Property
Public Sub SelectByValue(ByVal lb As ListBox, ByVal val As Object)
lb.SelectedItem = Nothing
Dim item As Object
For Each item In lb.Items
If Me.GetValue(item) = val Then
lb.SelectedItem = item
Exit Sub
End If
Next
End Sub
Public Function GetValue(ByVal obj As Object) As Object
If Me.valMemb = String.Empty Then Return obj
Dim pi As System.Reflection.PropertyInfo = _
obj.GetType().GetProperty(Me.valMemb)
If pi Is Nothing Then Return Nothing
Return pi.GetValue(obj, Nothing)
End Function
''' <summary>
''' Specifies the member returning value in the list control used by the dynamic combo editor.
''' </summary>
''' <param name="valueMemberPropertyName">The name of the property used as value member by the dynamic combo type editor.</param>
''' <remarks></remarks>
''' <history>
''' [afiq] 05/02/2004 Created
''' </history>
Public Sub New(ByVal valueMemberPropertyName As String)
Me.valMemb = valueMemberPropertyName
End Sub
End Class
''' <summary>
''' Specifies the member displayed in the list control used by the dynamic combo editor.
''' </summary>
''' <remarks></remarks>
''' <history>
''' [afiq] 05/02/2004 Created
''' </history>
<AttributeUsage(AttributeTargets.All)> _
Public Class DisplayMemberAttribute
Inherits Attribute
Private dispMemb As String
''' <summary>
''' Gets the name of the property displayed in the list control used by the dynamic combo editor.
''' </summary>
''' <value></value>
''' <remarks></remarks>
''' <history>
''' [afiq] 05/02/2004 Created
''' </history>
<Description("The property displayed in the list control used by the dynamic combo editor.")> _
Public ReadOnly Property DisplayPropertyName() As String
Get
Return Me.dispMemb
End Get
End Property
''' <summary>
''' Specifies the property displayed in the list control used by the dynamic combo editor.
''' </summary>
''' <param name="displayMemberPropertyName">The name of the property displayed in the dynamic combo type editor.</param>
''' <remarks></remarks>
''' <history>
''' [afiq] 05/02/2004 Created
''' </history>
Public Sub New(ByVal displayMemberPropertyName As String)
Me.dispMemb = displayMemberPropertyName
End Sub
End Class
#End Region