Problem with PropertyGrid and Collection of Strings



I created a collection derived from CollectionBase that is just made up of
strings, called "StringList". I have another object that has as a member
one of these StringList.

If I assign that object to a PropertyGrid, click on the collection editor
("...") and try to add a new string, I get an error message "Constructor on
type System.String not found.".

Any ideas what I'm missing? This works fine with any of the value types,
but classes like "String" and "IPEndPoint" do not have constructors, so how
can I tell the PropertyGrid collection editor to instantiate new objects
with a default value?


Here's my "StringList" class for reference

using System;
using System.Collections;

namespace TestStringListAdd
public class StringList : CollectionBase
public StringList()
: base()
public void Add( String str )
this.List.Add( str );

public void Remove( String str )
this.List.Remove( str);

public string this[ int index ]
get{return (String)this.List[index];}





Joe White

The IDE's collection editor probably expects to be able to instantiate
the collection items using their default constructor, and then modify
the items' properties. Since strings are immutable, this won't work.
You could make your collection store objects that each have a property
of type String, instead of storing the Strings directly, and it would
probably work. Otherwise, you'll probably have to do some extra work to
get it going -- custom type converters and stuff like that.

Unfortunately, I don't know much about type converters, so I can't help
you much. Sorry.

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