Hi
I've just upgraded some Type Editors from 1.1 to 2.0 and whilst they compile
OK, I'm not getting any results in the test harness PropertyGrid. Usually
when you select a particular property, the ellipsis appears at the end of the
cell and this is not heppening.
I was therefore wondering if there had been changes in TypeEditors between
..NET versions 1.1 and 2.0 that I hadn't hear about.
One of the Type Editors is shown below:
Imports System.Windows.Forms
Imports System.Drawing.Design
Imports System.ComponentModel
Public Class UIFilenameEditor
Inherits System.Drawing.Design.UITypeEditor
'@ <summary>Opens the dialogue in a modal window</summary>
'@ <remarks>
'@ <para>Since it is natural for the filename editor to open a file
dialogue which is a modal window, this editor is set to have Modal
style.</para>
'@ <para>This method seems to called when the cursor lands on a property
grid entry.</para>
'@ </remarks>
'@ <param name="context" type="ComponentModel.ITypeDescriptorContext">
'@ <para>The context is a
System.Windows.Forms.PropertyGridInternal.Property GridDescriptorGridEntry.</para>
'@ </param>
'@ <returns>Returns the 'style' to the calling property grid (or other
control)</returns>
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
'@ <summary>Thid core method provides the file dialogue
interface.</summary>
'@ <returns>The file name that has been selected.</returns>
<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 objFileDialogue As FileDialog
If context.PropertyDescriptor.Attributes(GetType(Save FileAttribute))
Is Nothing Then
objFileDialogue = New OpenFileDialog
Else
objFileDialogue = New SaveFileDialog
End If
objFileDialogue.Title = "Select " &
context.PropertyDescriptor.DisplayName
objFileDialogue.FileName = DirectCast(value, String)
Dim objFileDialogueFilterAttribute As FileDialogueFilterAttribute =
DirectCast(context.PropertyDescriptor.Attributes(G etType(FileDialogueFilterAttribute)), FileDialogueFilterAttribute)
If Not objFileDialogueFilterAttribute Is Nothing Then
objFileDialogue.Filter = objFileDialogueFilterAttribute.Filter
End If
Dim objFileDialogueCaptionAttribute As FileDialogueCaption =
DirectCast(context.PropertyDescriptor.Attributes(G etType(FileDialogueCaption)), FileDialogueCaption)
If Not objFileDialogueCaptionAttribute Is Nothing Then
objFileDialogue.Title = objFileDialogueCaptionAttribute.stuTitle
End If
If objFileDialogue.ShowDialog() = DialogResult.OK Then
value = objFileDialogue.FileName
End If
objFileDialogue.Dispose()
Return value
End Function
'@ <summary>An attribute class within UIFilenameEditor that sets the
filter on the file dialogue.</summary>
<AttributeUsage(AttributeTargets.Property)> _
Public Class FileDialogueFilterAttribute
Inherits Attribute
Private _stuFilter As String
'@ <summary>The filter to use in the file dialog in
UIFilenameEditor.</summary>
'@ <remarks>The following is an example of a stuFilter string: "Text
files (*.txt)|*.txt|All files (*.*)|*.*"</remarks>
Public ReadOnly Property Filter() As String
Get
Return _stuFilter
End Get
End Property
'@ <summary>Define a Filter for the UIFilenameEditor.</summary>
'@ <param name="stuFilter">The filter string to use in the file
dialog in UIFilenameEditor. The following is an example of a filter string:
"Text files (*.txt)|*.txt|All files (*.*)|*.*"</param>
Public Sub New(ByVal stuFilter As String)
MyBase.New()
_stuFilter = stuFilter
End Sub
End Class
'@ <summary>An attribute class within UIFilenameEditor that, if present,
changes the <i>open file dialogue</i> to a <i>save file dialogue</i>
control</summary>
<AttributeUsage(AttributeTargets.Property)> _
Public Class SaveFileAttribute
Inherits Attribute
End Class
'@ <summary>An attribute that sets the caption on the file dialogue
box</summary>
<AttributeUsage(AttributeTargets.Property)> _
Public Class FileDialogueCaption
Inherits Attribute
Private _stuCaption As String
'@ <param name="stuTitle">The string that will be placed in the
title bar of the dialogue</param>
Public Sub New(ByVal stuTitle As String)
_stuCaption = stuTitle
End Sub
Public ReadOnly Property stuTitle() As String
Get
Return _stuCaption
End Get
End Property
End Class
End Class
I created a test class to exercise each of the Type Editors that I've
written. The corresponding property in the test class is:
Private _stuFilename As String
<Category("File editors"), EditorAttribute(GetType(UIFilenameEditor),
GetType(UITypeEditor)), UIFilenameEditor.FileDialogueFilter("HTML
files|*.htm"), UIFilenameEditor.FileDialogueCaption("Select an HTML file")> _
Public Property stuFilename() As String
Get
Return _stuFilename
End Get
Set(ByVal stuFilename As String)
_stuFilename = stuFilename
End Set
End Property
Any clues anyone?
Thanks in advance.
Crispin
Bristol, UK.