Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 28th, 2004, 09:29 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Yugoslavia.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add node in ie treeview

Hi, i have a problem with adding nodes
Here is my code.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Not IsPostBack Then

            Dim cn As New SqlConnection(cnString)
            Dim cmd As New SqlCommand
            Dim objReader As SqlDataReader
            Dim strSQL As String

            strSQL = "select ID, NAME from Table1"
            With cmd
                .Connection = cn
                .CommandType = CommandType.Text
                .CommandText = strSQL
            End With

            cn.Open()
            objReader = cmd.ExecuteReader
            Dim n As New TreeNode

            While (objReader.Read)
                n.Text = objReader.Item("Name")
                n.ImageUrl = "bs.gif"
                n.Expandable = ExpandableValue.Always
                n.ExpandedImageUrl = "bo.gif"
                n.NodeData = objReader.Item("ID")
                tvwHelp.Nodes.Add(n)
            End While
        End If
    End Sub 'This is ok but I have a problem with next
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''

Private Sub tvwHelp_Expand(ByVal sender As Object, ByVal e As Microsoft.Web.UI.WebControls.TreeViewClickEventArg s) Handles tvwHelp.Expand

        Dim cn As New SqlConnection(cnString)
        Dim cmd As New SqlCommand
        Dim objReader As SqlDataReader
        Dim strSQL As String
        Dim nE As TreeNode
        Dim nodeRez As TreeNode

        nE = sender.nodes(e.Node.ToString)

        If nE.Nodes.Count = 0 Then

            strSQL = " select ID,SINAME as NAME from TOC " _
            & " where PARENTID =" & CInt(nE.NodeData.ToString) "

            With cmd
                .Connection = cn
                .CommandType = CommandType.Text
                .CommandText = strSQL
            End With

            cn.Open()
            objReader = cmd.ExecuteReader

            While objReader.Read
                nodeRez = New TreeNode
                nodeRez.Text = objReader.Item("Name")
                nodeRez.NodeData = objReader.Item("ID")
                nodeRez.Expandable = ExpandableValue.Always
                nE.Nodes.Add(nodeRez)
            End While
        Else
            nE.Expanded = True
        End If
    End Sub
''''''''''''''''''''''''
 tvwHelp_Expand works fine only for first time, but later when i want to expand any other child node i always get error:

 System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.

How can i solve this problem?
Thanks very much


Similar Threads
Thread Thread Starter Forum Replies Last Post
TreeView and SiteMap Node Order robzyc ASP.NET 1.0 and 1.1 Basics 0 May 19th, 2008 04:27 AM
How to Drag and Drop node from treeview to Datagri mohan_here C# 1 April 26th, 2007 12:41 PM
How to select a node or text from treeview MacDevv C# 2005 3 September 5th, 2006 05:23 AM
Focusing on a node in a treeview (C# application) themuffinman_swe C# 5 November 27th, 2005 09:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.