Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Casting error with extended treenode in treeview

Reply
Thread Tools

Casting error with extended treenode in treeview

 
 
Blaenzo
Guest
Posts: n/a
 
      06-19-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to access the Page from a TreeNode (treeview 's element) : addinga context menu to a treeview abargaddon ASP .Net Building Controls 0 01-17-2008 11:05 AM
Extended TreeNode Hakan Ugur ASP .Net 1 12-14-2007 07:07 PM
what is equivalent of vb.net treenode.nextnode property in asp.net webcontrols.treenode tanya foster ASP .Net 3 05-18-2006 05:58 PM
Inserting,Deleting and modyfing TreeNode Xml of Treeview naija naija ASP .Net 0 09-28-2004 01:50 AM
populating treeview menu from db(treenode not defined error) naijacoder naijacoder ASP .Net 1 09-15-2004 03:11 AM



Advertisments