Using Property Grid in a control and Expandable types are always readonly

B

Brian Young

Hi all.

I'm using the Property Grid control in a control to manage a windows service
we have developed here. The windows service runs a set of other jobs that
need to be managed. The control is used to view the state of the running
jobs and schedule new jobs. The control also runs in the context of
Internet Explorer (we do this so the administrators of the jobs can always
receive the latest control). The property grid is used to change the
properties of the jobs (so we could add new properties w/o having to recode
the UI).

My problem is with the expandable object type. We're using this type to
represent some job properties that need to be set together and are defined
by a set of business rules. The type has a custom UITypeEditor and I do
know how to set that up and use it in VB. The problem is that when the
control is hosted in IE, this property type is readonly and cannot be
modified. It can't be expanded to look at the sub-properties and the
ellispsis button is not available to get the editor. When run in an exe,
everything works as it is supposed to: I get an expandable property, the
ellipsis button shows and works, and I can change values directly for my
expandable properties.

Has anyone run into this problem? This is really annoying us as the only
way to get full functionality of this control is to run it in an executable
which is not the ideal case for us since this is part of our overall
deployment strategy. Is there something that is missing that I should do?

I've posted snippets of my code below:

**JobDef.vb**
Imports System
Imports System.Drawing
Imports System.Drawing.Design
Imports System.ComponentModel
Friend Class JobDefSort
Inherits BaseSorter
Public Sub New()
SortOrder = New String() {"ID", "Name", "Description", "JobType",
"Run"}
End Sub
End Class

<TypeConverter(GetType(JobDefSort))> _
Friend Class JobDef
Implements IBrowsable
Private mID As Long
Private mName As String
Private mDescription As String
Private mType As JobType
Private mRun As Date = "01/01/2000"
Public Sub New()
mType = New JobType
mID = -1
End Sub
Public Sub New(ByVal ID As Long, ByVal Name As String, ByVal Description
As String, _
ByVal Type As Integer, ByVal Interval As Integer, ByVal Time As
Date, _
ByVal Value As String, ByVal Range As String, ByVal Run As Date)
mType = New JobType(Type, Interval, Range, Value, Time)
mID = ID
mName = Name
mDescription = Description
mRun = Run
End Sub

<Description("Job Definition ID."), Category("System")> _
Public ReadOnly Property ID() As Long
Get
Return mID
End Get
End Property
<Description("Job Definition name."), Category("Data")> _
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
End Set
End Property
<Description("Job Definition Description."), Category("Data")> _
Public Property Description() As String
Get
Return mDescription
End Get
Set(ByVal Value As String)
mDescription = Value
End Set
End Property
<Description("Job Type."), Category("Type"), _
Editor(GetType(JobTypeEditor), GetType(UITypeEditor))> _
Public Property Type() As JobType
Get
Return mType
End Get
Set(ByVal Value As JobType)
mType = Value
End Set
End Property
<Description("When to start running this job."), Category("Data")> _
Public Property Run() As Date
Get
Return mRun
End Get
Set(ByVal Value As Date)
mRun = Value
End Set
End Property
End Class

**JobType.VB**
Imports System
Imports System.Drawing
Imports System.Drawing.Design
Imports System.ComponentModel
Imports System.Text
Imports System.Globalization
<TypeConverter(GetType(JobTypeConverter)), _
DefaultPropertyAttribute("Type")> _
Friend Class JobType
Public Enum eJobType
eONCE = 0
eMONTHLY_DOM = 1
eMONTHLY_DOW = 2
eWEEKLY = 3
eDAILY = 4
eINTERVAL = 5
End Enum
#Region "Variables"
Private mType As eJobType
Private mInterval As Integer
Private mTime As Date
Private mRange As String
Private mValue As String
#End Region
Sub New()
mType = eJobType.eONCE
mInterval = -1
mRange = vbNullString
mValue = vbNullString
mTime = System.DateTime.Now
End Sub
Sub New(ByVal Type As eJobType, ByVal Interval As Integer, _
ByVal Range As String, ByVal Value As String, ByVal Time As Date)
mType = Type
mInterval = Interval
mRange = Range
mValue = Value
mTime = Time
End Sub
Friend Sub SetValues(Optional ByVal Type As eJobType = eJobType.eONCE, _
Optional ByVal Interval As Integer = -1, _
Optional ByVal Range As String = vbNullString, _
Optional ByVal Value As String = vbNullString, _
Optional ByVal Time As Date = #1/1/2000#)
mType = Type
mInterval = Interval
mRange = Range
mValue = Value
mTime = Time
End Sub
#Region "Properties"
<Description("Type."), Category("Data")> _
Public ReadOnly Property Type() As eJobType
Get
Return mType
End Get
End Property
<Description("Interval."), Category("Data")> _
Public ReadOnly Property Interval() As Long
Get
Return mInterval
End Get
End Property
<Description("Time."), Category("Data")> _
Public Property Time() As Date
Get
Return mTime
End Get
Set(ByVal Value As Date)
mTime = Value
End Set
End Property
<Description("Range."), Category("Data")> _
Public ReadOnly Property Range() As String
Get
Return mRange
End Get
End Property
<Description("Value."), Category("Data")> _
Public ReadOnly Property Value() As String
Get
Return mValue
End Get
End Property
#End Region
End Class
Friend Class JobTypeConverter
Inherits System.ComponentModel.ExpandableObjectConverter
Protected SortOrder() As String
Public Overloads Overrides Function GetPropertiesSupported( _
ByVal context As ITypeDescriptorContext) As Boolean
Return True
End Function
Public Overloads Overrides Function GetProperties(ByVal context As
ITypeDescriptorContext, _
ByVal value As Object, ByVal attributes() As Attribute) As
PropertyDescriptorCollection
Dim properties As PropertyDescriptorCollection = _
TypeDescriptor.GetProperties(value, attributes)
Return properties.Sort(SortOrder)
End Function
Public Sub New()
SortOrder = New String() {"Type", "Interval", "Range", "Value", "Time"}
End Sub
'''
#Region "Variables"
#End Region
'''
#Region "Properties"
#End Region
End Class

**JobTypeEditor.VB**
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Design
Imports System.ComponentModel
Imports System.Windows.Forms.Design
Friend Class JobTypeEditor
Inherits UITypeEditor
Private _Service As IWindowsFormsEditorService = Nothing
Public Overloads Overrides Function GetEditStyle(ByVal context As
ITypeDescriptorContext) As UITypeEditorEditStyle
If Not context Is Nothing And Not context.Instance Is Nothing Then
Return UITypeEditorEditStyle.Modal
End If
Return MyBase.GetEditStyle(context)
End Function
Public Overloads Overrides Function EditValue(ByVal context As
ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As
Object) As Object
'Get a reference to the IWindowsFormsEditorService used to display the
UILongString form
_Service = CType(provider.GetService(GetType(IWindowsFormsEditorService)),
IWindowsFormsEditorService)
If Not _Service Is Nothing Then
'Create an instance of the custom UI form
Dim editor As JobTypeEdit = New JobTypeEdit
editor.Type = (context.Instance).Type
'Initialise the custom editor form with the current value of the target
Employee.Comments property
' editor.Val = (context.Instance).type
'Show the UILongString editor form
_Service.ShowDialog(editor)
'If the user has clicked on the OK button then the string they were editing
is returned to the property grid
Return editor.Type
End If
Return MyBase.EditValue(context, provider, value)
End Function
End Class

**JobTypeEdit.vb**
Imports System.Text
Friend Class JobTypeEdit
Inherits System.Windows.Forms.Form
Private mType As JobType
Private mbCancel As Boolean = True
#Region " Windows Form Designer generated code "
.... snipped ...
#End Region
#Region "Properties"
.... snipped ...
#End Region
#Region "Save"
.... snipped ...
#End Region
#Region "Load"
.... snipped ...
#End Region
#Region "Events"
.... snipped ...
#End Region
End Class

Thanks much.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top