Hi,
I have a class which I am feeding to the propertygrid, and I am
exposing a Mesh object from my class for the propertygrid to display. I
want the propertygrid to show the values (when you expand the property)
and allow those values to be edited. My code is below. The grid is
showing the values but they are read-only, although the other
properties for the rest of my class are editable.
Public Class MeshConverter
Inherits TypeConverter
Public Overrides Function CanConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As
System.Type) As Boolean
If sourceType.ToString = "System.String" Then
Return True
Else
Return MyBase.CanConvertFrom(context, sourceType)
End If
End Function
Public Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
Return False
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 destinationType Is Nothing Then
Throw New ArgumentNullException("destinationType")
ElseIf value.ToString = "Microsoft.DirectX.Direct3D.Mesh" Then
Return "Mesh Object"
Else
Return MyBase.ConvertTo(context, culture, value,
destinationType)
End If
End Function
Public Overrides Function GetProperties(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal value As Object,
ByVal attributes() As System.Attribute) As
System.ComponentModel.PropertyDescriptorCollection
Return TypeDescriptor.GetProperties(GetType(Mesh)) '
MyBase.GetProperties(context, value, attributes)
End Function
Public Overrides Function GetPropertiesSupported(ByVal context As
System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
I am new to this typeconverter stuff. My class property looks like
this:
<TypeConverter(GetType(MeshConverter))> _
Public Property Mesh() As Direct3D.Mesh
Get
Return _mesh
End Get
Set(ByVal value As Direct3D.Mesh)
_mesh = value
End Set
End Property
This is the property I want to be able to view and edit within the
propertygrid when I pass the propertygrid my main class.
Can anybody see what I am doing wrong?
Thanks,
Richy