Casting error with extended treenode in treeview

Discussion in 'ASP .Net Web Controls' started by Blaenzo, Jun 19, 2006.

  1. Blaenzo

    Blaenzo Guest

    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
    Blaenzo, Jun 19, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. naijacoder naijacoder
    Replies:
    1
    Views:
    666
    naijacoder naijacoder
    Sep 15, 2004
  2. naija naija
    Replies:
    0
    Views:
    495
    naija naija
    Sep 28, 2004
  3. tanya foster
    Replies:
    3
    Views:
    3,722
    tanya foster
    May 18, 2006
  4. Hakan Ugur

    Extended TreeNode

    Hakan Ugur, Dec 14, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    462
    bruce barker
    Dec 14, 2007
  5. abargaddon
    Replies:
    0
    Views:
    1,051
    abargaddon
    Jan 17, 2008
Loading...

Share This Page