Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3619800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:55:28+00:00 2026-05-18T22:55:28+00:00

I am writing an extended treeview, just with a few extra properties in my

  • 0

I am writing an extended treeview, just with a few extra properties in my TreeNode class with designtime support.

The code is allmost ready, but at the moment I’m completely stuck with the following code.
Everything I try at this point results in (another) exception…

Maybe anyone has an idea how to go futher? I don’t know it anymore

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing.Design;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
using System.Windows.Forms;

namespace MyProject.Forms { public class MenuTreeView : TreeView { public MenuTreeView() { // }

[Editor(typeof(MenuTreeNodeCollectionEditor), typeof(UITypeEditor))] //[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public new TreeNodeCollection Nodes { get { return base.Nodes; } } } [Serializable] [DefaultProperty("Text")] [TypeConverter(typeof(MenuTreeNodeConverter))] public class MenuTreeNode : TreeNode, ISerializable { private string description = ""; public MenuTreeNode() : base() { // } public MenuTreeNode(string text) : base(text) { // } public MenuTreeNode(string text, string description) : base(text) { this.description = description; } public MenuTreeNode(string text, MenuTreeNode[] children) : base(text, children) { // } public override object Clone() { object clone = base.Clone(); MenuTreeNode node = clone as MenuTreeNode; if (node != null) { node.Description = Description; return node; } else return clone; } void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { Serialize(info, context); } protected override void Deserialize(SerializationInfo info, StreamingContext context) { Description = info.GetString("Description"); base.Deserialize(info, context); } protected override void Serialize(SerializationInfo info, StreamingContext context) { info.AddValue("Description", Description); base.Serialize(info, context); } [DefaultValue("")] public string Description { get { return description; } set { description = value; } } } public class MenuTreeNodeConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type type) { if (type == typeof(string)) { return true; } return base.CanConvertFrom(context, type); } public override bool CanConvertTo(ITypeDescriptorContext context, Type type) { if (type == typeof(InstanceDescriptor) || type == typeof(string)) { return true; } return base.CanConvertTo(context, type); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo info, object value) { if (value != null && value is string) { string[] items = ((string)value).Split(','); return new MenuTreeNode(items[0], items[1]); } return base.ConvertFrom(context, info, value); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo info, object value, Type type) { MenuTreeNode node = value as MenuTreeNode; if (value != null) { if (type == typeof(string)) { return node.Text + "," + node.Description; } else if (type == typeof(InstanceDescriptor)) { ConstructorInfo constructor = typeof(MenuTreeNode).GetConstructor(new Type[] { typeof(string), typeof(string) }); return new InstanceDescriptor(constructor, new object[] { node.Text, node.Description }, true); } } return base.ConvertTo(context, info, value, type); } } public class MenuTreeNodeCollectionEditor : CollectionEditor { public MenuTreeNodeCollectionEditor(Type t) : base(t) { // } protected override Type CreateCollectionItemType() { return typeof(MenuTreeNode); } protected override Type[] CreateNewItemTypes() { return new Type[] { typeof(MenuTreeNode) }; } protected override object CreateInstance(Type itemType) { if (itemType == typeof(MenuTreeNode)) { return new MenuTreeNode(); } return base.CreateInstance(itemType); } protected override string GetDisplayText(object value) { MenuTreeNode node = value as MenuTreeNode; if (node != null) { return "MenuTreeNode: " + node.Text; } return base.GetDisplayText(value); } }

}

[edit]
After moving the Treeview to another project, all goes fine. Don’t ask me why…

But: only the properties Text and Description are saved, because the designer does not create local variables for each added node. How can I achieve this?

[edit]
Finally, I got it to work! thanks to this: http://netcode.ru/dotnet/?lang=&katID=30&skatID=283&artID=7827

The solution was to remove the typeof(string) from the TypeConvertor, and when the type is InstanceDescriptor, just return the default constructor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:55:28+00:00Added an answer on May 18, 2026 at 10:55 pm

    Finally, I got it to work! thanks to this article: http://netcode.ru/dotnet/?lang=&katID=30&skatID=283&artID=7827

    The solution was to remove the typeof(string) from the TypeConvertor, and when the type is InstanceDescriptor, just returning the default constructor does the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a movie script editor using AvalonEdit. I extended the DocumentLine class
Writing Classic ASP code in JScript has a lot going for it: more humane
Writing documentation in html requires some code examples. What to do with characters that
When writing code, I often place debug messages in the code. The debug messages
I am developing a Math application which can be extended by writing python scripts.
I'm looking at writing monitoring code that runs inside a Java application and periodically
I'm writing a library in PHP 5.3, the bulk of which is a class
I am working with a legacy C library that can be extended by writing
I'm writing an application in C that can be extended at runtime by means
I'm writing a abstract file parser (C#) which is extended by two concrete parsers.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.