Event not work with new class that Inherits TreeNode

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

I define my class as below, I don't need to override the "new(text as
string)" method as it not inherited, but I don't know why.



-------------------

Public Class TreeNode2

Inherits System.Windows.Forms.TreeNode

Private m_UID As Integer

ReadOnly Property HoldData()

Get

Return m_UID

End Get

End Property



Sub New(ByVal txt As String, ByVal UID As Integer)

MyBase.New(txt)

m_UID = UID

End Sub

End Class

-------------------



I create an instance of the new class in the code below



--------------------

Dim parentnode As TreeNode2

parentnode = New TreeNode2("1st Tree Node ", -1)

----------------



I then respond to the event of the treeview, it is at this point I have a
problem as VB.Net says UID is not a member of TreeNode2



-----------------



Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

Dim mynode As TreeNode2

mynode = CType(e.Node, TreeNode2)

MessageBox.Show(mynode.UID)

End Sub
 
Brian said:
I define my class as below, I don't need to override the "new(text as
string)" method as it not inherited, but I don't know why.



-------------------

Public Class TreeNode2

Inherits System.Windows.Forms.TreeNode

Private m_UID As Integer

ReadOnly Property HoldData()

Get

Return m_UID

End Get

End Property



Sub New(ByVal txt As String, ByVal UID As Integer)

MyBase.New(txt)

m_UID = UID

End Sub

End Class

-------------------



I create an instance of the new class in the code below



--------------------

Dim parentnode As TreeNode2

parentnode = New TreeNode2("1st Tree Node ", -1)

----------------



I then respond to the event of the treeview, it is at this point I have a
problem as VB.Net says UID is not a member of TreeNode2



-----------------



Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

Dim mynode As TreeNode2

mynode = CType(e.Node, TreeNode2)

MessageBox.Show(mynode.UID)

End Sub
 
Hi,

You never added a UID property. The read only property HoldData
returns the UID.

Ken
---------------
 
Back
Top