custom editor for TreeView nodes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello you,
I need Your HELP.
I have my own TreeView Nodes Editor, in order to add 'MyTreeNode'', like
node which are ComboBox and so.
I have two classes. one inherit from 'TreeView' and the other from 'TreeNode'.
In 'MyTreeView' i override 'Nodes' (keyword- new) in order to open my custom
editor.
In public partial class MyTreeView : TreeView, I use the next statement:

[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(typeof(NodesTypeEditor), typeof(UITypeEditor)),
]
new public TreeNodeCollection Nodes
{
get { return base.Nodes; }
set
{
TreeNode[] myTreeNodeArray = new
TreeNode[((TreeNodeCollection)value).Count];
((TreeNodeCollection)value).CopyTo(myTreeNodeArray, 0);
((TreeNodeCollection)value).Clear();
this.Nodes.AddRange(myTreeNodeArray);
}
}
but the DesignerSerializationVisibility create the next code, which produce
casting error on run time:
MyCheckTreeNode myCheckTreeNode1 = ((MyCheckTreeNode)(new
TreeNode("TreeNode")));
I need it to be :
MyCheckTreeNode myCheckTreeNode1 = new MyCheckTreeNode("TreeNode");
In the editor i use TreeView and PropertyGrid. the code in 'Add CheckBox
Node' is:
treeView1.Nodes.Add(new MyCheckTreeNode("TreeNode"));
How can i fix it???

Please Help me. I need it fast.

Thanks,

Ran S'
 
Hi,

You may possibly need to modify the node collection by overriding the
..Add and .AddRange to create your MyCheckTreeNode.
 
Dear glenhong,

it cann't be done!

in order to override 'Add' and so, i must inherit from 'TreeViewCollection',
which is not inhetitable. we can't also create a custom collection using
'CollectionBase', since the tree won't work...
 
Back
Top