BYTE-Smasher
Member
I'm hoping that there's someone here who has some extensive experience with the PropertyGrid control.... I've been trying to figure out this problem for the past 4 days, and all I'm hitting is roadblocks....
I'm writing an editor for some developers, and attempting to use the propgrid as a nice enhancement to my editor... I came across TypeConverters when I was trying to figure out how to make expandable property lists from my classes... the ExpandableObjectConverter gave me (seemingly) what I was looking for as shown in the following diagram:
Properties
-------------
+Color
|----Red
|----Green
\----Blue
Text
+Size
|----Width
\----Height
you'll notice the color and size properties which branch off into their components... this is EXACTLY what I wanted... until i tried doing it with a class that had other classes as objects... I wanted these nested classes to behave the same way and expand... but there was no + sign on the propertygrid beside them.... I was devastated! All of my work had amounted to nothing!! and just when I had gotten my hopes up...
What I wanted was more like the following... which I've seen in programs using the property grid before... and am quite confused on how to achieve:
Code:
Properties
-------------
+Background
|----+Color1
| |----Red
| |----Green
| \----Blue
|----+Color2
| |----Red
| |----Green
| \----Blue
|Text
+Size
|----Width
\----Height
Note the fast that there are multiple layers to the tree... this is what I want... and I've managed to acheive when I stick classes from the .NET framework into my primary class as properties..... my question is this: why do my classes not act the same way, and how do I make them act the same way?? ...
The folowing is the TypeConverter I'm applying to my guiLocation class:
And here's the location class:
If ANYONE has any experience with this type of thing, can you please help me out?? I'm stumped this is an important project.... thanks
I'm writing an editor for some developers, and attempting to use the propgrid as a nice enhancement to my editor... I came across TypeConverters when I was trying to figure out how to make expandable property lists from my classes... the ExpandableObjectConverter gave me (seemingly) what I was looking for as shown in the following diagram:
Properties
-------------
+Color
|----Red
|----Green
\----Blue
Text
+Size
|----Width
\----Height
you'll notice the color and size properties which branch off into their components... this is EXACTLY what I wanted... until i tried doing it with a class that had other classes as objects... I wanted these nested classes to behave the same way and expand... but there was no + sign on the propertygrid beside them.... I was devastated! All of my work had amounted to nothing!! and just when I had gotten my hopes up...
What I wanted was more like the following... which I've seen in programs using the property grid before... and am quite confused on how to achieve:
Code:
Properties
-------------
+Background
|----+Color1
| |----Red
| |----Green
| \----Blue
|----+Color2
| |----Red
| |----Green
| \----Blue
|Text
+Size
|----Width
\----Height
Note the fast that there are multiple layers to the tree... this is what I want... and I've managed to acheive when I stick classes from the .NET framework into my primary class as properties..... my question is this: why do my classes not act the same way, and how do I make them act the same way?? ...
The folowing is the TypeConverter I'm applying to my guiLocation class:
VB.NET:
Friend Class guiLocationConverter : Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If (sourceType Is GetType(String)) Then Return True
Return MyBase.CanConvertFrom(context, sourceType)
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
Debug.WriteLine("ConvertFrom")
If TypeOf value Is String Then
Try
Dim s As String = CType(value, String)
Dim versionParts() As String
Dim VersionString As String = ""
versionParts = Split(s, ",")
If Not IsNothing(versionParts) Then
Dim _GuiLocation As GuiLocation = New GuiLocation
If Not IsNothing(versionParts(0)) Then _GuiLocation.Left = versionParts(0)
If Not IsNothing(versionParts(1)) Then _GuiLocation.Top = versionParts(1)
Return _GuiLocation
End If
Catch ex As Exception
Throw New ArgumentException("Can not convert '" + value + "' to type guiLocation")
End Try
End If
Return MyBase.ConvertFrom(context, culture, value)
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
Debug.WriteLine("ConvertTo")
If (destinationType Is GetType(System.String) AndAlso TypeOf value Is GuiLocation) Then
Dim _GuiLocation As GuiLocation = CType(value, GuiLocation)
Return _GuiLocation.Left & "," & _GuiLocation.Top
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean
If (destinationType Is GetType(GuiLocation)) Then Return True
Return MyBase.CanConvertFrom(context, destinationType)
End Function
End Class
VB.NET:
<TypeConverter(GetType(guiLocationConverter))> _
Public Class GuiLocation
Private mvarTop As Integer
Private mvarLeft As Integer
Public Property Top() As Integer
Get
Return mvarTop
End Get
Set(ByVal Value As Integer)
mvarTop = Value
End Set
End Property
Public Property Left() As Integer
Get
Return mvarLeft
End Get
Set(ByVal Value As Integer)
mvarLeft = Value
End Set
End Property
End Class
If ANYONE has any experience with this type of thing, can you please help me out?? I'm stumped this is an important project.... thanks