PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Extending TreeView and TreeNode
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
Extending TreeView and TreeNode
![]() |
Extending TreeView and TreeNode |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hello,
I've posted the same question on msdn forums, but I'll try it here too since I'm lost here. I'm creating a custom TreeView with custom TreeNode classes nested. This is a sample what I want to do: MyTreeView class: public partial class MyTreeView : TreeView { public MyTreeView() { InitializeComponent(); Nodes.Add(new MyTreeNode()); } private class MyTreeNode : TreeNode { public MyTreeNode() : base("MyNode") { } } } When I drag this control to a windows form, It will show the correct node inside (created in the constructor), but it will also create this line on form's InitializeComponent() method: WindowsApplication2.MyTreeView.MyTreeNode myTreeNode1 = new System.Windows.Forms.TreeNode("MyNode"); The problem here is that 1) the nested type is private, 2) there is no cast from TreeNode to MyTreeNode. Since I don't need the nodes to show up at design time, there is any way to not create them only when at design? Or is there any other way to do this? Thanks Pedro |
|
|
|
#2 |
|
Guest
Posts: n/a
|
ferreira,
If you worry only about the designer generated code the easiest would be to hide the Nodes porperty of the base class and apply attributes not to serialize it: [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public new TreeNodeCollection Nodes { get { return base.Nodes; } } The user can still see and set the Nodes property from code thought, but this you cannot faight because the property exist in the base class and it is not even virtual. "ferreira" <ferreira@discussions.microsoft.com> wrote in message news:3A07B4BD-18BE-4B1C-991F-76C259AA4C10@microsoft.com... > Hello, > > I've posted the same question on msdn forums, but I'll try it here too > since > I'm lost here. > > I'm creating a custom TreeView with custom TreeNode classes nested. > > This is a sample what I want to do: > > MyTreeView class: > > public partial class MyTreeView : TreeView > { > public MyTreeView() > { > InitializeComponent(); > > Nodes.Add(new MyTreeNode()); > } > > private class MyTreeNode : TreeNode > { > public MyTreeNode() : > base("MyNode") > { > } > } > } > > When I drag this control to a windows form, It will show the correct node > inside (created in the constructor), but it will also create this line on > form's InitializeComponent() method: > > WindowsApplication2.MyTreeView.MyTreeNode myTreeNode1 = new > System.Windows.Forms.TreeNode("MyNode"); > > The problem here is that 1) the nested type is private, 2) there is no > cast > from TreeNode to MyTreeNode. > > Since I don't need the nodes to show up at design time, there is any way > to > not create them only when at design? > > Or is there any other way to do this? > > Thanks > > Pedro |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks for your reply Stoitcho Goutsev!
That was exactly what I was looking for. Just tested and it worked fine! Thanks! Pedro Ferreira "Stoitcho Goutsev (100)" wrote: > ferreira, > > If you worry only about the designer generated code the easiest would be to > hide the Nodes porperty of the base class and apply attributes not to > serialize it: > > [Browsable(false)] > [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] > public new TreeNodeCollection Nodes > { > get > { > return base.Nodes; > } > > } > > The user can still see and set the Nodes property from code thought, but > this you cannot faight because the property exist in the base class and it > is not even virtual. > > "ferreira" <ferreira@discussions.microsoft.com> wrote in message > news:3A07B4BD-18BE-4B1C-991F-76C259AA4C10@microsoft.com... > > Hello, > > > > I've posted the same question on msdn forums, but I'll try it here too > > since > > I'm lost here. > > > > I'm creating a custom TreeView with custom TreeNode classes nested. > > > > This is a sample what I want to do: > > > > MyTreeView class: > > > > public partial class MyTreeView : TreeView > > { > > public MyTreeView() > > { > > InitializeComponent(); > > > > Nodes.Add(new MyTreeNode()); > > } > > > > private class MyTreeNode : TreeNode > > { > > public MyTreeNode() : > > base("MyNode") > > { > > } > > } > > } > > > > When I drag this control to a windows form, It will show the correct node > > inside (created in the constructor), but it will also create this line on > > form's InitializeComponent() method: > > > > WindowsApplication2.MyTreeView.MyTreeNode myTreeNode1 = new > > System.Windows.Forms.TreeNode("MyNode"); > > > > The problem here is that 1) the nested type is private, 2) there is no > > cast > > from TreeNode to MyTreeNode. > > > > Since I don't need the nodes to show up at design time, there is any way > > to > > not create them only when at design? > > > > Or is there any other way to do this? > > > > Thanks > > > > Pedro > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

