Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / January 2006

Tip: Looking for answers? Try searching our database.

CollectionEditor and recursive propriety

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bp - 25 Jan 2006 13:11 GMT
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 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(DesignerSerializationVisibility.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(DesignerSerializationVisibility.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
bp - 26 Jan 2006 14:25 GMT
I have found a way to make it work.

I have overriden the EditValue method of the editor and added the following
line :

context.OnComponentChanged();

But I don't know exactly why there was a problem...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.