Event not work with new class that Inherits TreeNode

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
 
B

Brian

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
 
K

Ken Tucker [MVP]

Hi,

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

Ken
---------------
 

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