Treeview issue

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Treeview issue

  1. #1
    Join Date
    Mar 2006

    Treeview issue

    Ok guys here is what I am running into...

    I have a application with a treeview I want to fill at runtime, the problem, due to the size of the records I can't fill it all at once or it will take FOREVER to run, so wat I want to do is wait to fill in the child nodes till after the parent node is selected and a new parameter is passed in (for example expand node1 and then pass in the key value through to another query and these results are the value of the children). My partner got it working in ASP but it doesn't seem to work in client. Here is the ASP code

    Imports System.Data
    Imports System.Data.SqlClient
    'Imports CasesByYear
    Imports DISCLSV100
    Imports System.Runtime.Remoting
    Imports System.Runtime.Remoting.Channels
    Imports System.Runtime.Remoting.Channels.Tcp
    Imports System.Runtime.Remoting.Channels.http
    Partial Class CaseByYearIndustry
        Inherits System.Web.UI.Page
        'written by Dayhuff Group/Fonny Lasmana 05/01/2006
        'Private cCasesByYear As New CasesByYear.CasesByYear
        Private cCasesByYear As New CasesByYear
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim caseChannel As TcpClientChannel = New TcpClientChannel()
                ChannelServices.RegisterChannel(caseChannel, False)
            Catch ex As Exception
            End Try
                RemotingConfiguration.RegisterWellKnownClientType(GetType(CasesByYear), "tcp://disiis:49153/CasesByYear")
            Catch ex As Exception
            End Try
            If (Not Page.IsPostBack) Then
                Dim dsPopulateYear As DataSet = cCasesByYear.getCasesByYear
                For Each row As DataRow In dsPopulateYear.Tables(0).Rows
                    Dim nodeYear As New TreeNode( _
                        row("CaseByYearCount").ToString(), row("CaseByYearCountValue").ToString())
                    nodeYear.PopulateOnDemand = True
                Next row
            End If
        End Sub
        Protected Sub PopulateNote(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles tvCaseByYearIndustry.TreeNodePopulate
            'if year is selected the industry child node will be displayed
            If e.Node.Depth = 0 Then
                Dim theYear As String = e.Node.Value
                Dim dsIndustryPurpose As DataSet = cCasesByYear.getCasesByYearIndustry(theYear)
                Dim row As DataRow
                For Each row In dsIndustryPurpose.Tables(0).Rows
                    Dim nodeIndustry As TreeNode = New _
                        TreeNode(row("CaseByYearIndustryandCount").ToString(), row("CaseByYearIndustryandCountValue").ToString())
                    nodeIndustry.PopulateOnDemand = True
                Next row
                'if industry is selected the case no leaf node will be displayed
            ElseIf e.Node.Depth = 1 Then
                Dim theNode As String = e.Node.Value
                Dim theYear As String = theNode.Substring(0, 4)
                Dim ci_code As String = theNode.Substring(5, 2)
                Dim dsCaseNo As DataSet = cCasesByYear.getCasesByYearIndustryCaseNo(theYear, ci_code)
                Dim row As DataRow
                For Each row In dsCaseNo.Tables(0).Rows
                    Dim nodeCaseNo As TreeNode = New _
                    nodeCaseNo.PopulateOnDemand = False
                    nodeCaseNo.NavigateUrl = "findcase.aspx?searchcaseno=" & row("case_number").ToString().Substring(0, 7)
                Next row
            End If
        End Sub
    End Class
    Thanks guys

  2. #2
    Join Date
    Mar 2006
    You need to use the Before Expand property, this is what I have used:

    Private Sub tvCaseByYearIndustry_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvCaseByYearIndustry.BeforeExpand

    ' Populate Node

    If e.Node.GetNodeCount(False) > 0 Then
    e.Node.ImageIndex = 1
    e.Node.SelectedImageIndex = 1
    e.Cancel = True
    End If

    End Sub

  3. #3
    Join Date
    Mar 2006
    Thanks for the help but I'm a little confused about your code

    a.) where is the populate function
    b.) Why am I using image indexes?

    also if you explain or step through it that would help


  4. #4
    Join Date
    Mar 2006
    Image indexes was from my own code as I have images in my windows application, can ignore them.

    I created a PopulateNode function for my Windows application. I am using Windows so the protected web method may do the trick and won't need to use before expand. However for each row you will have to add a blank node, the code I used was as follows:

    With dtCategories
    For Each drCategory In .Rows
    ndeCategory = New TreeNode
    ndeCategory.Tag = drCategory("CategoryID")
    ndeCategory.Text = drCategory("Name")
    ' Where no parent id add root category
    If intParentid = 0 Then
    ' or add embedded category
    End If
    ' Add embedded category where children exist
    If drCategory("Children") > 0 Then
    End If
    End With

    when expanding the node, you will have to delete this node first.

Similar Threads

  1. TreeView Component and XML
    By asilter in forum ASP.NET
    Replies: 0
    Last Post: 05-01-2006, 11:59 AM
  2. Replies: 0
    Last Post: 03-08-2006, 08:26 AM
  3. Replies: 0
    Last Post: 09-19-2001, 06:48 AM
  4. Shift TreeView nodes inside TreeView window
    By Valentin Bakhov in forum VB Classic
    Replies: 0
    Last Post: 02-12-2001, 08:03 AM
  5. Thin Client and Treeview
    By Martin Kaschke in forum Enterprise
    Replies: 3
    Last Post: 04-10-2000, 05:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center