Question : Decrease load time of tree in vb.net 2003

I am trying to load a tree from a dataset.  The code is below.   Problem is it is taking so long to load the code .  How can I speed up the load.  Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
Private Sub treeloadall()
        objDS.Clear()
        Dim servicetype
        servicetype = "SERVICE"
        '    If Program = "ContactLog" Then
        daSections = New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT convert(varchar(10),dbo.tblMHCIntake.dtmIntake,101) as intakedate,dtmintake, DATENAME(dw, dbo.tblMHCIntake.dtmIntake) AS dayname FROM         dbo.tblMHCIntake   where dtmintake > '01/01/2005'ORDER BY dbo.tblMHCIntake.dtmIntake DESC", Connection1)
        daContent = New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT tblPatient.strLName + ', ' + tblPatient.strFName AS name, CONVERT(varchar(10), tblMHCIntake.dtmIntake, 101) AS intakedate, DATENAME(dw, dbo.tblMHCIntake.dtmIntake) AS dayname, tblMHCIntake.dtmIntake, tblMHCIntake.strStaff, CONVERT(varchar(10), tblPatient.dtmDOB, 101) AS dtmdob, tblPatient.strPatientId, tblMHCIntakeDetail.lngIntakeId FROM tblMHCIntake INNER JOIN tblMHCIntakeDetail ON tblMHCIntake.lngIntakeId = tblMHCIntakeDetail.lngIntakeId INNER JOIN tblLUMHCData ON tblMHCIntakeDetail.lngDataId = tblLUMHCData.lngDataID RIGHT OUTER JOIN tblPatient ON tblMHCIntake.lngPatientId = tblPatient.lngPatientId WHERE (tblMHCIntake.dtmIntake > '1/1/2005')ORDER BY tblMHCIntake.dtmIntake DESC", Connection1)
        datype = New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT tblMHCIntakeDetail.lngIntakeId , tblMHCIntakeDetail.lngDataId, tblLUMHCData.strData FROM tblMHCIntake INNER JOIN tblMHCIntakeDetail ON tblMHCIntake.lngIntakeId = tblMHCIntakeDetail.lngIntakeId INNER JOIN tblLUMHCData ON tblMHCIntakeDetail.lngDataId = tblLUMHCData.lngDataID RIGHT OUTER JOIN tblPatient ON tblMHCIntake.lngPatientId = tblPatient.lngPatientId WHERE (tblMHCIntake.dtmIntake > '1/1/2005') and tblLUMHCData.strtype = '" & servicetype & "'", Connection1)




      
        Try
            daSections.Fill(objDS, "dtSections")
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

        Try
            daContent.Fill(objDS, "dtContent")
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

        Try

            counttype = datype.Fill(objDS, "dtType")

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
        '  If Program = "contactLog" Then
        ' System.Threading.Thread.Sleep(100000)
        '  End If
        objDS.Relations.Add("SectionToContent", _
        objDS.Tables("dtSections").Columns("dtmIntake"), _
        objDS.Tables("dtContent").Columns("dtmIntake"))


        objDS.Relations.Add("SectionToType", _
              objDS.Tables("dtContent").Columns("lngIntakeId"), _
              objDS.Tables("dtType").Columns("lngIntakeId"))




        nodenew = New TreeNode
        nodenew.Text = "Create new Client Contact..."
        nodenew.Tag = "new"
        TreeView1.Nodes.Add(nodenew)

        For Each rowSupp In objDS.Tables("dtSections").Rows

            nodeSupp = New TreeNode
            nodeSupp.Text = rowSupp("dtmIntake") & " - " & rowSupp("dayname")
            nodeSupp.Tag = "Intake Date"
            Dim dotw
            nodeSupp.Expand()
            TreeView1.Nodes.Add(nodeSupp)
            ProgressBar1.Maximum = objDS.Tables("dtContent").Rows.Count  'this will set the max value to avoid the error you got before

            For Each rowProd In rowSupp.GetChildRows("SectionToContent")
                nodeProd = New TreeNode
                nodeProd.Text = rowProd("intakedate") & " - " & rowProd("strStaff") & " - " & rowProd("name") & " - " & rowProd("dtmdob") & " - " & rowProd("strPatientid")
                nodeProd.Tag = rowProd("lngIntakeID")

                nodeSupp.Nodes.Add(nodeProd)
                For Each rowType In rowProd.GetChildRows("SectionToType")
                    nodetype = New TreeNode
                    nodetype.Text = rowType("strData")
                    nodeProd.Nodes.Add(nodetype)
                Next

                Application.DoEvents()

                ProgressBar1.Value += 1 'this will increase the value after every object completed
            Next

        Next



        ' Timer1.Stop()
        'TreeView1.ExpandAll()
        ' TreeView1.SelectedNode = TreeView1.Nodes.Item(2)
        TreeView1.Focus()
        pageload = True
    End Sub

Answer : Decrease load time of tree in vb.net 2003

You can gain some time by using BeginUpdate()/EndUpdate():
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.beginupdate.aspx
Random Solutions  
 
programming4us programming4us