Hi I have done some reserch how to implement the above,however I get lost in more complex examples I have found in codeproject and so on.
What I want to do is when showing my propertyGrid I want to have the ability to have a collection editor of strings.
For example sake lets say I want to have a collection of car Models.
THe problem i have is that i see the collection editor but when I press Add I get
"Constructor on type system.string not found"
AM I missing something
If so could somebody show me with a bit of code
Thanks in advance for any suggestions.
I have done as follows:
'//Collection class #Region "Imports Directives" Imports System.Collections.ObjectModel Imports System Imports System.Collections.Generic #End Region
'//some stuff here I have omitted. end class
Public Class Car private mCars as mycollectionofT(of string)
end class |
then i map the property grid to the car object.

How can Implement a string Collection Editor in a property Grid
Marco72463
Hi vbjunkie,
System.Design.dll assembly has a built-in StringCollectionEditor, use it instead of creating your own CollectionEditor for a collection of strings:
<Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")> _
Public Class MyStringCollection
' Implementation of your string collection
End Class
Regards,
-chris
Juan Pablo Gil
Here's a codeproject article that details the creation of custom CollectionEditor:
http://www.codeproject.com/csharp/DzCollectionEditor.asp#CollectionEditor
To get most of the PropertyGrid control, try this article:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dndotnet/html/usingpropgrid.asp
Regards,
-chris
Tony Valenti
vbjunkie
cbas
Sure, I'll take your code offline and test it later on my notebook, to see if it works on 2.0 framework; rightnow the machine I'm using has no 2.0 framework installed. I'll update you later.
Regards,
-chris
medarch
Hi VBJunkie,
Did you ever get a solution to your question I'm trying to do something similar to your origianl post but seem to get stuck at a similar point.
Any help would be appriciated
Nelson Drueding
Guys have a look at the msdn page for this.
http://msdn2.microsoft.com/en-us/library/42737xf2(VS.80).aspx
take a look at the community content. A neat solution is given there for C#.
Geethan
locknload
kaliyappan
Hi vbjunkie,
I tried your codes with my VB.NET2005, and it works fine. Can you give me the details of your problem regarding the codes you posted or can you email me the zip containing the project at gwapo@models.com
Thanks,
-chris
Michael Pritchard
Thanks for your reply.
I have emailed you a zip file containing a small project.
Press on people and then add in the collection editor and you get the error
Thanks again
Shail_P
PersonConverter class
Public
Class PersonConverter Inherits ExpandableObjectConverter
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 False 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 Else Return MyBase.CanConvertFrom(context, destinationType) 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 Dim Parts() As StringParts =
CType(value, String).Split(New Char() {","}) Dim p As New Person(Parts(0), Parts(1), Parts(3)) Return p End Function Public Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, _ ByVal culture As System.Globalization.CultureInfo, _ ByVal value As Object) As Object
Return MyBase.ConvertFrom(context, culture, value) End Function Public Overrides Function GetPropertiesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean Return True 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 MyBase.GetProperties(context, value, attributes) End FunctionEnd
ClassImports
SystemImports
System.ComponentModelImports
System.Collections.ObjectModel<EditorAttribute(
GetType(System.ComponentModel.Design.CollectionEditor), _ GetType(System.Drawing.Design.UITypeEditor))> _Public
Class PersonCollection(Of t) Inherits Collection(Of t)end
ClassImports
System.ComponentModelImports
System.ComponentModel.Design<TypeConverter(
GetType(PersonConverter)), _Serializable()> _
Public
Class Person Private mFirstName As String Private mLastName As String Private mAge As String Private mPeople As PersonCollection(Of String)
Public Sub New(ByVal FirstName As String, _ ByVal LastName As String, _ ByVal age As Integer)mFirstName = FirstName.Trim
mLastName = LastName.Trim
mAge = age
End Sub Public Sub New()mFirstName =
String.EmptymLastName =
String.EmptymAge = 0
End Sub Public Property FirstName() As String Get Return mFirstName End Get Set(ByVal value As String)mFirstName = value
End Set End Property
Public Property LastName() As String Get Return mLastName End Get Set(ByVal value As String)mLastName = value
End Set End Property
Public Property Age() As Integer Get Return mAge End Get Set(ByVal value As Integer)mAge = value
End Set End Property Public Property People() As PersonCollection(Of String) Get Return mPeople End Get Set(ByVal value As PersonCollection(Of String))mPeople = value
End Set End PropertyEnd
Classin the form added a property grid and
Private
mPerson As New Person Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.PropertyGrid1.SelectedObject = mPerson End Subget the error pressing add
any ideas
Johann6879
Just to say that i still get the error.
I have found a link that explain but i cannot make it work under 2.0 framework
http://blogs.msdn.com/toub/archive/2004/10/12/241277.aspx
can you help
thanks
Fakhar Khan
However I would like to learn how to make one as i am planning to use the property grid quite a bit and i wanted to learn how to make my own collection editor.
Would it be too much too ask you to show me how to do it
thanks alot