Problem with PropertyGrid and string based Collection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry

    #1

    Problem with PropertyGrid and string based Collection

    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 "Constructo r on
    type System.String not found.".

    Any ideas what I'm missing? If it can't create a new object of one of the
    built-in base types something is wrong.

    Thanks,
    Terry

    Here's my "StringList " class for reference

    using System;

    using System.Collecti ons;

    namespace TestStringListA dd

    {

    /// <summary>

    ///

    /// </summary>

    public class StringList : CollectionBase

    {

    public StringList()

    : base()

    {

    }

    public void Add( String str )

    {

    this.List.Add( str );

    }

    public void Remove( String str )

    {

    this.List.Remov e( str);

    }

    public string this[ int index ]

    {

    get

    {

    return (String)this.Li st[index];

    }

    }

    }

    }


  • Terry

    #2
    Re: Problem with PropertyGrid and string based Collection

    I'll follow up on my own post with some additional information.

    I discovered that "String" does not have a default constructor. Neither do
    a number of other Framework classes, e.g. "IPEndPoint ". So, if I were to
    make a collection class of "IPEndPoint " derived from CollectionBase I run
    into the same problem.

    So, I guess the real question is how to handle these classes that don't have
    default constructors so PropertyGrid can construct new instances of them?

    Thanks!
    Terry
    "Terry" <cheerio12345@h otmail.com> wrote in message
    news:%23GJJ6xVX DHA.1744@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > 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 "Constructo r on
    > type System.String not found.".
    >
    > Any ideas what I'm missing? If it can't create a new object of one of the
    > built-in base types something is wrong.
    >
    > Thanks,
    > Terry
    >
    > Here's my "StringList " class for reference
    >
    > using System;
    >
    > using System.Collecti ons;
    >
    > namespace TestStringListA dd
    >
    > {
    >
    > /// <summary>
    >
    > ///
    >
    > /// </summary>
    >
    > public class StringList : CollectionBase
    >
    > {
    >
    > public StringList()
    >
    > : base()
    >
    > {
    >
    > }
    >
    > public void Add( String str )
    >
    > {
    >
    > this.List.Add( str );
    >
    > }
    >
    > public void Remove( String str )
    >
    > {
    >
    > this.List.Remov e( str);
    >
    > }
    >
    > public string this[ int index ]
    >
    > {
    >
    > get
    >
    > {
    >
    > return (String)this.Li st[index];
    >
    > }
    >
    > }
    >
    > }
    >
    > }
    >
    >[/color]


    Comment

    Working...