PLEASE: Problem with TreeView, TreeNode Inherit

F

Frank Uray

Hi all

I have made my own Treeview Class with some additional
properties.
Now I am trying to clone Treenodes (Root), and it works
fine if I use System.Windows.Forms.TreeNode. If I use
my own class and debug it I see in the Locals Window
that the nodes have been cloned, but nothing happens
in the TreeView...
Following I have pasted the code of the class and how
I am testing it.

Thanks for any help!
Regards
Frank

-*********** The class
Public Class Cls_firstTreeView
Inherits System.Windows.Forms.TreeView
Implements ICloneable

Public Shadows Property SelectedNode() As
Cls_firstTreeNode
Get
Return CType(MyBase.SelectedNode,
Cls_firstTreeNode)
End Get
Set(ByVal Value As Cls_firstTreeNode)
MyBase.SelectedNode = Value
End Set
End Property

Public Function Clone() As Object Implements
ICloneable.Clone
Return Me.MemberwiseClone
End Function

End Class

Public Class Cls_firstTreeNode
Inherits System.Windows.Forms.TreeNode

Private var_Key As String
Private var_Key1 As String
Private var_Key2 As String
Private var_Key3 As String
Private var_Key4 As String
Private var_Key5 As String
Private var_PK As Integer

Public Overrides Function Clone() As Object
Return Me.MemberwiseClone
End Function

Public Sub New(Optional ByVal Text As String = "",
Optional ByVal Key As String = "", Optional ByVal Key1 As
String = "", Optional ByVal Key2 As String = "", Optional
ByVal Key3 As String = "", Optional ByVal Key4 As String
= "", Optional ByVal Key5 As String = "", Optional ByVal
PK As Integer = 0)
MyBase.New(Text)
var_Key = Key
var_Key1 = Key1
var_Key2 = Key2
var_Key3 = Key3
var_Key4 = Key4
var_Key5 = Key5
var_PK = PK
End Sub

Public Shadows Function Add(ByVal Text As String,
ByVal Key As String, Optional ByVal Key1 As String = "",
Optional ByVal Key2 As String = "", Optional ByVal Key3 As
String = "", Optional ByVal Key4 As String = "", Optional
ByVal Key5 As String = "", Optional ByVal PK As Integer =
0) As Cls_firstTreeNode
MyBase.Nodes.Add(Text)
var_Key = Key
var_Key1 = Key1
var_Key2 = Key2
var_Key3 = Key3
var_Key4 = Key4
var_Key5 = Key5
var_PK = PK
End Function

Public Shadows Function Add(ByVal TreeNode As
Cls_firstTreeNode) As Integer
MyBase.Nodes.Add(TreeNode)
var_Key = Key
var_Key1 = Key1
var_Key2 = Key2
var_Key3 = Key3
var_Key4 = Key4
var_Key5 = Key5
var_PK = PK
End Function

Public Property Key() As String
Get
Return var_Key
End Get
Set(ByVal Value As String)
var_Key = Value
End Set
End Property

Public Property Key1() As String
Get
Return var_Key1
End Get
Set(ByVal Value As String)
var_Key1 = Value
End Set
End Property

Public Property Key2() As String
Get
Return var_Key2
End Get
Set(ByVal Value As String)
var_Key2 = Value
End Set
End Property

Public Property Key3() As String
Get
Return var_Key3
End Get
Set(ByVal Value As String)
var_Key3 = Value
End Set
End Property

Public Property Key4() As String
Get
Return var_Key4
End Get
Set(ByVal Value As String)
var_Key4 = Value
End Set
End Property

Public Property Key5() As String
Get
Return var_Key5
End Get
Set(ByVal Value As String)
var_Key5 = Value
End Set
End Property

Public Property PK() As Integer
Get
Return var_PK
End Get
Set(ByVal Value As Integer)
var_PK = Value
End Set
End Property

End Class

-*********** How I am testing
Dim MyTreeView As New
firstTreeView.Cls_firstTreeView()
Dim MyRootNode1 As New
firstTreeView.Cls_firstTreeNode("Root X1")
MyRootNode1.Key = "Key Root X1"
Dim MyRootNode2 As New
firstTreeView.Cls_firstTreeNode("Root X2")
MyRootNode2.Key = "Key Root X2"
Dim MyChildNode1 As New
firstTreeView.Cls_firstTreeNode("Child X1")
MyChildNode1.Key = "Key Child X1"
Dim MyChildNode2 As New
firstTreeView.Cls_firstTreeNode("Child X2")
MyChildNode2.Key = "Key Child X2"

MyRootNode1.Nodes.Add(MyChildNode1)
MyRootNode2.Nodes.Add(MyChildNode2)
MyTreeView.Nodes.Add(MyRootNode1)
MyTreeView.Nodes.Add(MyRootNode2)

Dim RootNodes As New
firstTreeView.Cls_firstTreeNode()
Me.TreeView1.BeginUpdate()
For Each RootNodes In MyTreeView.Nodes
Me.TreeView1.Nodes.Add(CType(RootNodes.Clone,
firstTreeView.Cls_firstTreeNode))
Next
Me.TreeView1.EndUpdate()
Me.TreeView1.Refresh()
 
B

Bharat Patel [MSFT]

Hi Frank,

I am not sure about your code as I have not recreated it here. However, we have
a knowledge base article which provides the step on how to extend TreeNode
class:

311318 HOW TO: Create a Key Property for a TreeView Node in Visual Basic .NET
http://support.microsoft.com/?id=311318

Please review this and modify your code accordingly and see how it works.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top