Question : Progress Bar will not fire while tree is loading in vb.net windows application

I'm having a problem getting my progress bar fire while I am loading a dataset.  How can I tie a progress bar to loading a tree.  I have attached my code below.  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:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
Private Sub frmMHContactLogAll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        treeload = False
        Connection1.Open()
        Me.Size = New Size((Me.MdiParent.Size.Width - 50), Me.MdiParent.Size.Height - 100)
        MHIntakeID = Nothing
        ' If Program() = "ClientContact" Then
        'Me.Width = Me.MdiParent.Size.Width - 80
        'Me.Height = 300
        'Me.Top = 250
        'Else
        '   Me.Width = Me.MdiParent.Size.Width - 80
        '  Me.Height = Me.MdiParent.Size.Height - 150
        ' TreeView1.Height = Me.MdiParent.Size.Height - 150
        'End If
        Timer1.Enabled = True
       
        Me.Show()

        ' treeloadall()

     

    End Sub
 
    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)


        '   Else
        '       daContent = New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT tblPatient.strLName + ', ' + tblPatient.strFName AS name, CONVERT(varchar(10), tblMHCIntake.dtmIntake, 101) AS intakedate, 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 tblPatient.lngPatientId = '" & SqlParametersDB.Name.lngpatientid & "' 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  tblPatient.lngPatientId = '" & SqlParametersDB.Name.lngpatientid & "' and tblLUMHCData.strtype = '" & servicetype & "'", Connection1)
        '       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 dbo.tblMHCIntake.lngPatientId = '" & SqlParametersDB.Name.lngpatientid & "'  ORDER BY dbo.tblMHCIntake.dtmIntake DESC", Connection1)



        '   End If
        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
            Dim counttype
            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)
            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

            Next

        Next


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

Answer : Progress Bar will not fire while tree is loading in vb.net windows application

Why is the progressbar value changing is in Timer1_Tick? You should do it in the main code itself:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
ProgressBar1.maximum = rowSupp.GetChildRows.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() queue

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