Collection editor of the propertyGrid

R

Rohan

I need to use the Collection editor of the propertyGrid, but i can't
this to work, i looked around on the NET on collection and I am kinda
lost. i have this so far, i don't know what i should do next

Thank you


Public class frmColor

Dim xColors As New myColors

'Form Load event
PropertyGrid1.SelectedObject = xColors

End Class


Public Class myColors

Dim CustomC As CC_Collection

<TypeConverter(GetType(CollectionConverter)), DisplayName("test")>
_
Public Property test() As CC_Collection
Get
Return CustomC
End Get
Set(ByVal value As CC_Collection)
CustomC = value
End Set
End Property

End Class

Public Class CC_Collection
Private _name As String
Private _Color As Color

Public Sub New(ByVal [Name] As String, ByVal CColor As Color)
_name = Name
_Color = CColor
End Sub

Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property

Public Property CColor() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property

End Class
 
V

VisualHint

Hello Rohan,

you should explain what you are trying to do exactly, because in your
code sample, you have no collection at all and you apply
CollectionConverter (which is not an editor btw) to a property of type
CC_Collection which is a simple class containing a color and a string.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://
www.visualhint.com/index.php/fieldpackeditor)
 
R

Rohan

Hi VisualHint,

Hi,

So what I want to do is to use the collection editor in the property
gird for fill a collection that contains Name and color in this case.

You can see here in this example that I have a structure that contains
name and color. And the when I use the Add function it adds the
appropriate information in to the mynewcolor array which and contain
up to 10 elements. For this is work I a form that contains textbox and
a button, so the user can enter and text then pick a color and then
press ADD. I am already using a the propertygird, I can implement a
collection that would allow me to do this!



Public Structure Mycolors
Dim CName As String
Dim MyColor As Color
End Structure

Dim mynewcolor(10) As Mycolors
Dim i as Integer =0

Public Sub Add(ByVal name As String, ByVal xColor As Color)
mynewcolor(i).CName = name
mynewcolor(i).MyColor = xColor
i=i+1
End Sub


I hope you do understand

Thank you

Hello Rohan,

you should explain what you are trying to do exactly, because in your
code sample, you have no collection at all and you apply
CollectionConverter (which is not an editor btw) to a property of type
CC_Collection which is a simple class containing a color and a string.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List -http://www.propertygridresourcelist.com
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://www.visualhint.com/index.php/fieldpackeditor)

I need to use the Collection editor of the propertyGrid, but i can't
this to work, i looked around on the NET on collection and I am kinda
lost. i have this so far, i don't know what i should do next
Thank you
Public class frmColor
Dim xColors As New myColors
'Form Load event
PropertyGrid1.SelectedObject = xColors
End Class
Public Class myColors
Dim CustomC As CC_Collection
<TypeConverter(GetType(CollectionConverter)), DisplayName("test")>
_
Public Property test() As CC_Collection
Get
Return CustomC
End Get
Set(ByVal value As CC_Collection)
CustomC = value
End Set
End Property
End Class
Public Class CC_Collection
Private _name As String
Private _Color As Color
Public Sub New(ByVal [Name] As String, ByVal CColor As Color)
_name = Name
_Color = CColor
End Sub
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property CColor() As Color
Get
Return _Color
End Get
Set(ByVal value As Color)
_Color = value
End Set
End Property
End Class
 
V

VisualHint

Rohan,

well, if I had to explain you how to do it, I would tell you what is
in the article you are mentioning. If you tried to follow it, you are
not explaining for what you experience some difficulties. It involves
TypeDescriptors, TypeConverters and custom PropertyDescriptors.

Other than that I see that you are using a structure for your name/
color pair. You can do it, but be aware that it will add an additional
constraint to your code. The grid won't be able to edit it directly
and you will need a TypeConverter that supports the CreateInstance
method. Use a class if you want to avoid that.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC (http://www.visualhint.com/
index.php/propertygrid)
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com
Home of Smart FieldPackEditor.Net / DateTimePicker replacement (http://
www.visualhint.com/index.php/fieldpackeditor)
 

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