By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Bind a class to Property Grid - No setter executed

P: n/a
Hello group,

I design a class to bind it to a property grid for easy modification
of some settings. My problem is now that I want to raise an event when
a settings has been changed.
Thats not a problem with some "normal" properties (see property
DisplayGrid). But when I use a subclass and TypeConverter the setter
of the property is not called.
Set(ByVal value As LineSetting)
m_Limit1 = value
RaiseEvent Limit1Changed(Me, m_Limit1)
End Set
And therefore no event fired.

I already added the attribute
NotifyParentPropertyAttribute(True)
to the subclass but no change.

Here is my code:

Imports System.ComponentModel
Imports System.Drawing

Public Class Setting
#Region "Private members"

Private m_DisplayGrid As Boolean = True
Private m_Limit1 As New LineSetting(False, Color.AntiqueWhite)

#End Region

#Region "Events"
Public Event DisplayGridChanged(ByVal sender As Object, ByVal e As
Boolean)
Public Event Limit1Changed(ByVal sender As Object, ByVal e As
LineSetting)
#End Region
''' <summary>
''' Display grid on Chart
''' </summary>
<CategoryAttribute("General"), _
DefaultValueAttribute(True), _
DescriptionAttribute("Show a grid.")_
Public Property DisplayGrid() As Boolean
Get
Return m_DisplayGrid
End Get
Set(ByVal value As Boolean)
m_DisplayGrid = value
RaiseEvent DisplayGridChanged(Me, m_DisplayGrid)
End Set
End Property

<CategoryAttribute("Limits"), _
Editor(GetType(LineEditor),
GetType(System.Drawing.Design.UITypeEditor)), _
DescriptionAttribute("Show Limit 1")_
Public Property Limit1() As LineSetting
Get
Return m_Limit1
End Get
Set(ByVal value As LineSetting)
m_Limit1 = value
RaiseEvent Limit1Changed(Me, m_Limit1)
End Set
End Property

End Class

<TypeConverter(GetType(LineConverter))_
Public Class LineSetting
Private m_Show As Boolean
Private m_Color As Color

''' <summary>
''' Gets or sets a value indicating whether this <see
cref="LineSetting" /is show.
''' </summary>
Public Property Show() As Boolean
Get
Return m_Show
End Get
Set(ByVal value As Boolean)
m_Show = value
End Set
End Property
Public Property Color() As Color
Get
Return m_Color
End Get
Set(ByVal value As Color)
m_Color = value
End Set
End Property

''' <summary>
''' Initializes a new instance of the <see cref="LineSetting" />
class.
''' </summary>
Public Sub New()
' set default values
m_Show = False
m_Color = Drawing.Color.AliceBlue
End Sub

''' <summary>
''' Initializes a new instance of the <see cref="LineSetting" />
class.
''' </summary>
''' <param name="show">if set to <c>true</c[show].</param>
''' <param name="color">The color.</param>
Public Sub New(ByVal show As Boolean, ByVal color As Color)
' set values
m_Show = show
m_Color = color
End Sub
End Class

Friend Class LineConverter
Inherits ExpandableObjectConverter
Public Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
If (destinationType Is GetType(LineSetting)) Then
Return True
Else
Return MyBase.CanConvertTo(context, destinationType)
End If
End Function
Public Overrides Function ConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
If TypeOf value Is LineSetting Then
Dim myLimitSetting As LineSetting = CType(value,
LineSetting)
Return myLimitSetting.Show '
'& "," & myLimitSetting.Color.ToString
Else
Return MyBase.ConvertTo(context, culture, value,
destinationType)
End If
End Function
End Class
Friend Class LineEditor
Inherits System.Drawing.Design.UITypeEditor
Public Overrides Sub PaintValue(ByVal e As
System.Drawing.Design.PaintValueEventArgs)
Dim myChartLine As LineSetting
Dim fillRegion As New Region(e.Bounds)
' get setting to draw
myChartLine = CType(e.Value, LineSetting)

If myChartLine.Show = True Then
Dim myBrush As SolidBrush
myBrush = New SolidBrush(myChartLine.Color)
e.Graphics.FillRegion(myBrush, fillRegion)
Else
' draw a red cross to indicate false
e.Graphics.DrawLine(Pens.Red, e.Bounds.Left + 1,
e.Bounds.Bottom - 1, e.Bounds.Right - 1, e.Bounds.Top + 1)
End If

End Sub

Public Overrides Function GetPaintValueSupported(ByVal context As
System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
-------------------------

And this is the code within the form

Public Class Form1
Private OptionsPropertyGrid As System.Windows.Forms.PropertyGrid
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim mySettings As New Setting

AddHandler mySettings.Limit1Changed, AddressOf Limit1Changed
AddHandler mySettings.DisplayGridChanged, AddressOf
DisplayGridChanged

OptionsPropertyGrid = New PropertyGrid()
OptionsPropertyGrid.Size = New Size(310, 500)
OptionsPropertyGrid.Dock = DockStyle.Fill
Me.Size = New Size(310, 500)
Me.Controls.Add(OptionsPropertyGrid)
Me.Text = "Options Dialog"
OptionsPropertyGrid.SelectedObject = mySettings
OptionsPropertyGrid.PropertySort =
PropertySort.CategorizedAlphabetical
End Sub
Public Sub Limit1Changed(ByVal sender As Object, ByVal e As
LineSetting)
Debug.WriteLine("Limit 1 changed")
End Sub
Public Sub DisplayGridChanged(ByVal sender As Object, ByVal e As
Boolean)
Debug.WriteLine("Display Grid changed")
End Sub
End Class

------------------------

Any help ? Thank you

Greetings,

Hans
Mar 27 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.