I am having a problem with objects that have other objects as properties on a property grid. Now when I display ths object clsPropsFrame on the property grid, everything shows up as expected, except when I try to edit the x,y,or z of location which is of type clsPropsVec3, it ignores the change. What's strange is that when I type the vector in as a string (like "0,16,0"), it changes. I have the following code:
I noticed that when I changed a component of clsPropsVec3, the property change in clsPropsFrame does not get executed. I tried making it fire of an event when a component is changed in clsPropsVec3, with the following additional code:
but for some reason it ever fires off the ValueChanged event
So how can I make the sub properties of clsPropsVec3 work?
VB.NET:
'//////////////////Object Component///////////////////////////
<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class clsPropsVec3
Inherits ExpandableObjectConverter
Private refvec As TV_3DVECTOR
Public Sub New()
refvec = New TV_3DVECTOR(0, 0, 0)
End Sub
Public Sub New(ByVal vec As TV_3DVECTOR)
refvec = New TV_3DVECTOR(vec.x, vec.y, vec.z)
End Sub
Public Shared Widening Operator CType(ByVal Vec As TV_3DVECTOR) As clsPropsVec3
Return New clsPropsVec3(Vec)
End Operator
Public Shared Widening Operator CType(ByVal props As clsPropsVec3) As TV_3DVECTOR
Return props.refvec
End Operator
Public Property X() As Single
Get
Return refvec.x
End Get
Set(ByVal value As Single)
refvec.x = value
End Set
End Property
Public Property Y() As Single
Get
Return refvec.y
End Get
Set(ByVal value As Single)
refvec.y = value
End Set
End Property
Public Property Z() As Single
Get
Return refvec.z
End Get
Set(ByVal value As Single)
refvec.z = value
End Set
End Property
Public Overrides Function ToString() As String
Return Strings.Format(refvec.x, "0.0") + ", " + Strings.Format(refvec.y, "0.0") + ", " + Strings.Format(refvec.z, "0.0")
End Function
Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If (sourceType.Equals(GetType(String))) Then
Return True
ElseIf (sourceType.Equals(GetType(clsPropsVec3))) Then
Return True
Else
Return MyBase.CanConvertFrom(context, sourceType)
End If
End Function
Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
If (destinationType.Equals(GetType(String))) Then
Return True
ElseIf (destinationType.Equals(GetType(clsPropsVec3))) Then
Return True
Else
Return MyBase.CanConvertTo(context, destinationType)
End If
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
If (TypeOf value Is String) Then
Dim txt As String = CType(value, String)
Dim fields() As String = txt.Split(CChar(","))
Try
Return New clsPropsVec3(New TV_3DVECTOR(CSng(fields(0)), CSng(fields(1)), CSng(fields(2))))
Catch
Throw New InvalidCastException(CStr(value))
End Try
ElseIf (TypeOf value Is TV_3DVECTOR) Then
Return DirectCast(value, clsPropsVec3)
Else
Return MyBase.ConvertFrom(context, culture, value)
End If
End Function
Public Overloads 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 (destinationType.Equals(GetType(String))) Then
Return value.ToString()
ElseIf (destinationType.Equals(GetType(clsPropsVec3))) Then
Return DirectCast(value, clsPropsVec3)
Else
Return MyBase.ConvertTo(context, culture, value, destinationType)
End If
End Function
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 Attribute() As Attribute) As PropertyDescriptorCollection
Return TypeDescriptor.GetProperties(value)
End Function
End Class
'///////////////Object Code//////////////////
<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class clsPropsFrame
Private refFrame As clsFrame
Public Changable As Boolean
Public Sub New(ByVal Frame As clsFrame, ByVal bolChangable As Boolean)
refFrame = Frame
Changable = bolChangable
End Sub
<ParenthesizePropertyName(True)> _
<Category("Design")> _
Public Property Name() As String
Get
If refFrame Is Nothing Then Return "<No Frame>"
Return refFrame.Name
End Get
Set(ByVal value As String)
If refFrame Is Nothing Then Exit Property
If Not Changable Then Exit Property
refFrame.Name(True) = value
End Set
End Property
<Category("Design")> _
Public Property Index() As Integer
Get
If refFrame Is Nothing Then Return -1
Return refFrame.Index
End Get
Set(ByVal value As Integer)
If refFrame Is Nothing Then Exit Property
If Not Changable Then Exit Property
refFrame.Index(True) = value
clsFrame.SortByIndex()
End Set
End Property
<Category("Layout")> _
<TypeConverter(GetType(clsPropsVec3))> _
Public Property Location() As clsPropsVec3
Get
If refFrame Is Nothing Then Return New TV_3DVECTOR(Single.NaN, Single.NaN, Single.NaN)
Return refFrame.Position(False)
End Get
Set(ByVal value As clsPropsVec3)
If refFrame Is Nothing Then Exit Property
If Not Changable Then Exit Property
refFrame.Position(False) = value
End Set
End Property
Public Overrides Function ToString() As String
Return "Frame {" + refFrame.Name + "}"
End Function
Public Sub Destroy()
refFrame = Nothing
Finalize()
End Sub
End Class
I noticed that when I changed a component of clsPropsVec3, the property change in clsPropsFrame does not get executed. I tried making it fire of an event when a component is changed in clsPropsVec3, with the following additional code:
VB.NET:
Public Property X() As Single
Get
Return refvec.x
End Get
Set(ByVal value As Single)
refvec.x = value
---------> RaiseEvent ValueChanged()
End Set
End Property
VB.NET:
Public Class clsPropsFrame
Private refFrame As clsFrame
------> private WithEvents vecPosition as clsPropsVec3
VB.NET:
Public Sub New(ByVal Frame As clsFrame, ByVal bolChangable As Boolean)
refFrame = Frame
--------> If Not (refFrame is Nothing) Then
--------> vecPosition = New clsPropsVec3(refFrame.Position(False))
--------> End If
Changable = bolChangable
End Sub
VB.NET:
Public Sub OnPositionChange() handles vecPosition.ValueChanged
Location = vecPosition
End Sub
but for some reason it ever fires off the ValueChanged event
So how can I make the sub properties of clsPropsVec3 work?