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.Componen tModel
Public Class UIFilenameEdito r
Inherits System.Drawing. Design.UITypeEd itor
'@ <summary>Open s 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="Component Model.ITypeDesc riptorContext">
'@ <para>The context is a
System.Windows. Forms.PropertyG ridInternal.Pro pertyGridDescri ptorGridEntry.</para>
'@ </param>
'@ <returns>Return s the 'style' to the calling property grid (or other
control)</returns>
Public Overloads Overrides Function GetEditStyle(By Val context As
ITypeDescriptor Context) As UITypeEditorEdi tStyle
If Not context Is Nothing AndAlso Not context.Instanc e Is Nothing Then
Return UITypeEditorEdi tStyle.Modal
'
End If
Return UITypeEditorEdi tStyle.None
End Function
'@ <summary>Thid core method provides the file dialogue
interface.</summary>
'@ <returns>The file name that has been selected.</returns>
<RefreshPropert ies(RefreshProp erties.All)> _
Public Overloads Overrides Function EditValue(ByVal context As
ITypeDescriptor Context, ByVal provider As System.IService Provider, ByVal
value As Object) As Object
If context Is Nothing OrElse provider Is Nothing OrElse
context.Instanc e Is Nothing Then
Return MyBase.EditValu e(provider, value)
End If
Dim objFileDialogue As FileDialog
If context.Propert yDescriptor.Att ributes(GetType (SaveFileAttrib ute))
Is Nothing Then
objFileDialogue = New OpenFileDialog
Else
objFileDialogue = New SaveFileDialog
End If
objFileDialogue .Title = "Select " &
context.Propert yDescriptor.Dis playName
objFileDialogue .FileName = DirectCast(valu e, String)
Dim objFileDialogue FilterAttribute As FileDialogueFil terAttribute =
DirectCast(cont ext.PropertyDes criptor.Attribu tes(GetType(Fil eDialogueFilter Attribute)), FileDialogueFil terAttribute)
If Not objFileDialogue FilterAttribute Is Nothing Then
objFileDialogue .Filter = objFileDialogue FilterAttribute .Filter
End If
Dim objFileDialogue CaptionAttribut e As FileDialogueCap tion =
DirectCast(cont ext.PropertyDes criptor.Attribu tes(GetType(Fil eDialogueCaptio n)), FileDialogueCap tion)
If Not objFileDialogue CaptionAttribut e Is Nothing Then
objFileDialogue .Title = objFileDialogue CaptionAttribut e.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 UIFilenameEdito r that sets the
filter on the file dialogue.</summary>
<AttributeUsage (AttributeTarge ts.Property)> _
Public Class FileDialogueFil terAttribute
Inherits Attribute
Private _stuFilter As String
'@ <summary>The filter to use in the file dialog in
UIFilenameEdito r.</summary>
'@ <remarks>The following is an example of a stuFilter string: "Text
files (*.txt)|*.txt|A ll files (*.*)|*.*"</remarks>
Public ReadOnly Property Filter() As String
Get
Return _stuFilter
End Get
End Property
'@ <summary>Defi ne a Filter for the UIFilenameEdito r.</summary>
'@ <param name="stuFilter ">The filter string to use in the file
dialog in UIFilenameEdito r. The following is an example of a filter string:
"Text files (*.txt)|*.txt|A ll files (*.*)|*.*"</param>
Public Sub New(ByVal stuFilter As String)
MyBase.New()
_stuFilter = stuFilter
End Sub
End Class
'@ <summary>An attribute class within UIFilenameEdito r that, if present,
changes the <i>open file dialogue</i> to a <i>save file dialogue</i>
control</summary>
<AttributeUsage (AttributeTarge ts.Property)> _
Public Class SaveFileAttribu te
Inherits Attribute
End Class
'@ <summary>An attribute that sets the caption on the file dialogue
box</summary>
<AttributeUsage (AttributeTarge ts.Property)> _
Public Class FileDialogueCap tion
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("Fi le editors"), EditorAttribute (GetType(UIFile nameEditor),
GetType(UITypeE ditor)), UIFilenameEdito r.FileDialogueF ilter("HTML
files|*.htm"), UIFilenameEdito r.FileDialogueC aption("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.