Help me to Invoke treeview with Background worker ?

vb.net , treeview , backgroundworker Mesquite, United States
  • 8 years ago

    Hi there ! i have some problem that want you all save me , right now .!.

    My Procedure code is : Sub LoadHistory() Dim NodeAir As TreeNode Dim NodeBok As TreeNode Dim NodeM As TreeNode Dim NodeB As TreeNode Dim NodeW As TreeNode Dim NodeWB As TreeNode Dim NodeWKind As TreeNode Dim NodeWBKind As TreeNode 'TreView.Nodes.Clear() System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False NodeAir = TreView.Nodes.Add("Airport") 'TreeView.Invoke(TreView.Nodes.Add("Airport")) NodeAir.BackColor = Color.FromArgb(255, 128, 0) NodeAir.ForeColor = Color.WhiteSmoke NodeBok = TreView.Nodes.Add("Bok Seng") NodeBok.BackColor = Color.FromArgb(255, 128, 0) NodeBok.ForeColor = Color.WhiteSmoke Dim ds As New DataSet() Dim ds1 As New DataSet() Dim ds2 As New DataSet() Dim db As New DBClass Dim P As New DbReportExp.COM.DbReport_Exp

        Dim ArrMonth As String() = New String() {"January", "Febury", "March", "April", "May", "June", "July", "August", "September", "Octomber", "November", "December"}
        'Dim ArrNum As String() = New String() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
        Dim ArrWeek As String() = New String() {"Week1", "Week2", "Week3", "Week4"}
        ds = db.Db_DistinctYear_Air
        If ds.Tables(0).Rows.Count > 0 Then
            For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                NodeM = NodeAir.Nodes.Add(ds.Tables(0).Rows(i).ItemArray(0).ToString)
                Dim sYear As String = ds.Tables(0).Rows(i).ItemArray(0).ToString
                For j As Integer = 0 To ArrMonth.Length - 1
                    NodeW = NodeM.Nodes.Add(ArrMonth(j).ToString)
    
                    For k As Integer = 0 To ArrWeek.Length - 1
                        Dim sBdate As Date : Dim sEdate As Date
                        P.Status = ArrWeek(k).ToString
                        P.IsYear = CInt(sYear)
                        P.IsMonth = ArrMonth(j).ToString
                        ds1 = db.Db_GetBDate_EDate_ByWeek_Air(P)
                        If ds1.Tables(0).Rows.Count > 0 Then
                            sBdate = ds1.Tables(0).Rows(0).ItemArray(0).ToString
                            sEdate = ds1.Tables(0).Rows(0).ItemArray(1).ToString
                            NodeW_Kind = NodeW.Nodes.Add(ArrWeek(k).ToString & " : " & sBdate & " To " & sEdate)
                            NodeW.ForeColor = Color.Red
                            ds2 = db.Db_GetKindName_ByWeek_Air(P)
    
                            If ds2.Tables(0).Rows.Count > 0 Then
                                For l As Integer = 0 To ds2.Tables(0).Rows.Count - 1
                                    NodeW_Kind.Nodes.Add(ds2.Tables(0).Rows(l).ItemArray(0).ToString).BackColor = Color.FromArgb(200, 255, 255)
                                Next
                                NodeW_Kind.ForeColor = Color.FromArgb(100, 100, 0)
                            Else
                                NodeW_Kind.ForeColor = Color.Silver
                            End If
                        Else
                            NodeW.ForeColor = Color.Silver
                        End If
    
                    Next
                Next
            Next
        End If
    
        ds = db.Db_DistinctYear_Bok
        If ds.Tables(0).Rows.Count > 0 Then
            For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                NodeB = NodeBok.Nodes.Add(ds.Tables(0).Rows(i).ItemArray(0).ToString)
                Dim sYear As String = ds.Tables(0).Rows(i).ItemArray(0).ToString
                For j As Integer = 0 To ArrMonth.Length - 1
                    NodeW_B = NodeB.Nodes.Add(ArrMonth(j).ToString)
    
                    For k As Integer = 0 To ArrWeek.Length - 1
                        Dim sBdate As Date : Dim sEdate As Date
                        P.Status = ArrWeek(k).ToString
                        P.IsYear = CInt(sYear)
                        P.IsMonth = ArrMonth(j).ToString
                        ds1 = db.Db_GetBdate_Edate_ByWeek_Bok(P)
                        If ds1.Tables(0).Rows.Count > 0 Then
                            sBdate = ds1.Tables(0).Rows(0).ItemArray(0).ToString
                            sEdate = ds1.Tables(0).Rows(0).ItemArray(1).ToString
                            NodeW_B_Kind = NodeW_B.Nodes.Add(ArrWeek(k).ToString & " : " & sBdate & " To " & sEdate)
                            ds2 = db.Db_GetKindName_ByWeek_Bok(P)
                            NodeW_B.ForeColor = Color.Red
                            If ds2.Tables(0).Rows.Count > 0 Then
                                For l As Integer = 0 To ds2.Tables(0).Rows.Count - 1
                                    NodeW_B_Kind.Nodes.Add(ds2.Tables(0).Rows(l).ItemArray(0).ToString).BackColor = Color.FromArgb(200, 255, 255)
                                Next
                                NodeW_B_Kind.ForeColor = Color.FromArgb(100, 100, 0)
                            Else
                                NodeW_B_Kind.ForeColor = Color.Silver
                            End If
                        Else
                            NodeW_B.ForeColor = Color.Silver
                        End If
                    Next
                Next
            Next
        End If
        TreView.ExpandAll()
    End Sub
    

    '''' Back GroundWorker Event Do Private Sub Bg_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) LoadHistory() End Sub

    Private Sub CmdDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDisplay.Click, RibbonMenuButton1.Click TreView.Nodes.Clear() BgWork.WorkerSupportsCancellation = True BgWork.RunWorkerAsync() End Sub

    '' When i click button Cmddisplay Error Say that "Action being performed on this control is being called from the wrong thread. Marshal to the correct thread using Control.Invoke or Control.BeginInvoke to perform this action."

    Please Code for me how to invoke Treeview with Background Worker like threading .... etc

    I need very urgent na .. Best Regard from

    Nimol Men ,, Cambodia

  • 8 years ago

    I wrote a simple, easy to use VB.Net 2005 program ,that will show you how to run background tasks using the Backgroundworker.

    Email me at:

    frankfortino@comcast.net

    and I send you a copy

  • 8 years ago

    Hi ffortino !

    Yes i really need it ! could u send it to my email : m.nimol@yahoo.com ?

    Best Regards ,

    Nimol Men (Cambodia)

  • 8 years ago

    hi please find the solution in the below site http://www.codeproject.com/KB/miscctrl/Virtual_Treeview.aspx. Hope this will help you [idea]

  • 8 years ago

    Yeah thanks :-) !

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“You can stand on the shoulders of giants OR a big enough pile of dwarfs, works either way.”