B
Blaenzo
Hi,
I just made an extended treenode that I want to add to my treenode.
On for example a 'SelectedNodeChanged' event, my selected treenode is
not my extended treenode anymore but a regular treenode.
Running the sample code below results in the following error:
"Unable to cast object of type 'System.Web.UI.WebControls.TreeNode' to
type 'MyNode'".
Seems quite basic to me, what do I do wrong?
Many thanks,
Martijn
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim objTreeNode As New MyNode
objTreeNode.Value = "value"
objTreeNode.Text = "text"
objTreeNode.OtherValue = "test"
TreeView1.Nodes.Add(objTreeNode)
End If
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Dim objTreeNode2 As MyNode
objTreeNode2 = TreeView1.Nodes(0)
lblOtherValue.Text = objTreeNode2.OtherValue
End Sub
End Class
Public Class MyNode
Inherits TreeNode
Public OtherValue As String
End Class
I just made an extended treenode that I want to add to my treenode.
On for example a 'SelectedNodeChanged' event, my selected treenode is
not my extended treenode anymore but a regular treenode.
Running the sample code below results in the following error:
"Unable to cast object of type 'System.Web.UI.WebControls.TreeNode' to
type 'MyNode'".
Seems quite basic to me, what do I do wrong?
Many thanks,
Martijn
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim objTreeNode As New MyNode
objTreeNode.Value = "value"
objTreeNode.Text = "text"
objTreeNode.OtherValue = "test"
TreeView1.Nodes.Add(objTreeNode)
End If
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Dim objTreeNode2 As MyNode
objTreeNode2 = TreeView1.Nodes(0)
lblOtherValue.Text = objTreeNode2.OtherValue
End Sub
End Class
Public Class MyNode
Inherits TreeNode
Public OtherValue As String
End Class