CollectionBase crash in UserControl


S

scottiedog

Hi,
When I add a derived class from CollectionBase to a user control, the
form that uses the user control failed out on designer window with
error, (To prevent possible data loss before loading the designer, the
following errors must be resolved). I can continue on with ignore
this error, but the collection dialog doesn't save my selection. And
it is missing (Collection) word in the property section of the user
control.

Here is the derived CollectionBase class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Test
{
[Serializable()]
public class TextCollection : CollectionBase
{
private string[] _items;

public TextCollection()
{
}

public TextCollection(string[] items)
{
_items = items;
}

}
}

The user control has this.


[Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design",
"System.Drawing.Design.UITypeEditor, System.Drawing")]
//[Description("Button Text Collection")]
public TextCollection TextItems
{
get { return _items; }
set
{
_items = value;
_max = _items.Count;

//more to do;
}
}

If I comment out the above TextItems property, the designer error no
longer shows up.

Can you spot what I'm doing wrong? Thanks.
 
Ad

Advertisements

P

Peter Duniho

scottiedog said:
Hi,
When I add a derived class from CollectionBase to a user control, the
form that uses the user control failed out on designer window with
error,

Doing what? Just showing the form? Or trying to edit the collection?
And what is the exception being thrown?
[...]
public class TextCollection : CollectionBase

Why would you inherit CollectionBase, and then do this:
{
private string[] _items;

If you want to maintain your own storage for the collection, there's no
point in inheriting CollectionBase. Conversely, if you're inheriting
CollectionBase, you don't need to declare your own storage for the
collection.
[...]
The user control has this.


[Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design",
"System.Drawing.Design.UITypeEditor, System.Drawing")]
//[Description("Button Text Collection")]
public TextCollection TextItems

Off the top of my head, I see no reason to expect the
StringCollectionEditor to correctly handle your arbitrary CollectionBase
sub-class.

Note that a community comment on MSDN suggests this for the property
attribute:

[Editor("System.Windows.Forms.Design.StringCollectionEditor,
System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a",
typeof(System.Drawing.Design.UITypeEditor))]

If that doesn't help, you need to post a more complete question. State
clearly how to reproduce the problem, including the exact steps required
and a concise-but-complete code example that reliably demonstrates the
problem. Also be sure to describe in detail the exact error message(s)
you get, including the specific exception involved.

Pete
 
Ad

Advertisements

S

scottiedog

Thanks for reply.

The error occurs during design time where designer will crash, just
displaying the form that contains the user control. As you said, by
just trying to show the form. Perhaps I don't have to inherit the
CollectionBase but I pick this up from an example somewhere. So
basically I need a string collection which can be editable by user at
design time with an editor dialog. I'll try the property attribute
you suggested and take out string array.
 

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