473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

CollectionEditor and recursive propriety

bp
I have developped a component with a propriety of type List<BaseItem> where
BaseItem is a generic class. Two classes inherit from BaseItem : Noeud and
Item. Class Noeud has also a propriety of type List<BaseItem> so that we can
build a tree of BaseItem and assign it to the component. I have a custom
collection editor to edit the component's propriety (I gave up my first idea
to implement my own CollectionForm!).

I have a problem : there is a strange behavior when I want to add some
BaseItems to the second level of the tree. Let's take an example : if I
create an original tree like this : Noeud1(Noeud2,Item1), close all the
editor forms, and then, try to add an item in the collection of Noeud2,
nothing happens. But if I add a second item in Noeud1 first, and then create
an item in Noeid2, it works !

Can someone help me, please ?

Here's my code :

#region Items

public class BaseItem
{
private string _name;

public string Name
{
get { return _name; }
set { _name = value; }
}
}

public class Noeud : BaseItem
{
private List<BaseItem> _items;

[Editor(typeof(MyEditor), typeof(UITypeEditor))]

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
public List<BaseItem> Items
{
get { return _items; }
set { _items = value; }
}

public Noeud()
{
_items = new List<BaseItem>();
}
}

public class Item : BaseItem
{
private string _misc;

public string Misc
{
get { return _misc; }
set { _misc = value; }
}
}
#endregion

#region Editor

public class MyEditor : CollectionEditor
{
public MyEditor(Type type)
: base(type)
{ }

protected override Type[] CreateNewItemTypes()
{
return new Type[] { typeof(Noeud), typeof(Item) };
}
}
#endregion

#region Component

public partial class MyComponent : Component
{
private List<BaseItem> _items;

[Editor(typeof(MyEditor), typeof(UITypeEditor))]

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
public List<BaseItem> Items
{
get { return _items; }
set { _items = value; }
}

public MyComponent()
{
InitializeComponent();
_items = new List<BaseItem>();
}

public MyComponent(IContainer container)
{
_items = new List<BaseItem>();
container.Add(this);

InitializeComponent();
}
}
#endregion
Jan 25 '06 #1
0 938

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: m. pollack | last post by:
Hi all I've been using the PropertyGrid to allow the user to edit a class object at runtime. The class object contains a custom strongly-typed collection, and I have written a subclass of...
2
by: m. pollack | last post by:
Hi all I've been using the PropertyGrid to allow the user to edit a class object at runtime. The class object contains a custom strongly-typed collection, and I have written a subclass of...
0
by: juststarter | last post by:
Hello all, here is my problem. I am using a property grid control (in a vb.net 2003 project) in which two properties are exposed : "editorStyle" and "events". The first property is used to select...
0
by: Andreas | last post by:
Hi! I'm using a custom collection with custom items to be edited with a custom CollectionEditor. This set of functionality is to be a part of a plugin for a SharpDevelop-based application. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.