CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    May 2013

    DataGridView and Threading - Desperate Help Needed

    Hi all,
    This is my first post so please be gentle, lol. So I've spent almost a week rewriting this code umpteen different ways and still cannot get it to work with threading. I can get it to work without multithreading, no problem. As soon as I thread it, even with a delegate, it breaks. Please, if you can shed some light on the problem I would be most grateful.
    I've purposely left out the delegate here hoping someone might see what's what. Basically I am trying to update a DGV with a row created in a thread. Class2 holds the function, setData, being called on the thread and Form1 holds the DGV. SetDataTable is the actual function in Form1 that sets the row's data in the DGV and gets called in Class2(I can do this right?). I've abridged the code for simplicity's sake. Please help.

    Public Class Class2
    	Public Sub setData()
    		    Dim dt1 As New DataTable()
                        dt1.Columns.Add(New DataColumn("", GetType(String)))
                        dt1.Columns.Add(New DataColumn("", GetType(String)))
                        dt1.Columns.Add(New DataColumn("", GetType(String)))
                        dt1.Columns.Add(New DataColumn("", GetType(String)))
                        Dim DataR As DataRow
                        Dim rowArray(4) As Object
                        DataR = dt1.Rows(0)
                        DataR.Item(0) = ipAddr
                        DataR.Item(1) = iptohost(ipAddr)
                        DataR.Item(2) = getMACAddress(ipAddr)
                        DataR.Item(3) = "True"
    	End Sub
    End class
    Public Class Form1
        Dim dt As New DataTable()
        Dim dr As DataRow
        Private Sub Initialize()
            dt.Columns.Add(New DataColumn("ComputerIP", GetType(String))) '0
            dt.Columns.Add(New DataColumn("ComputerName", GetType(String))) '1
            dt.Columns.Add(New DataColumn("ComputerMAC", GetType(String))) '2
            dt.Columns.Add(New DataColumn("Bandwidth", GetType(String)))
            dg1.DataSource = dt
            dr = dt.NewRow()
        End Sub
        Public Sub SetDataTable(ByVal table As DataTable)
                    dr.ItemArray = table.Rows(0).ItemArray
                Catch e As Exception
                End Try
            End If
        End Sub
        Public Sub dosomething()
    	GetComp as Class2
    	GetComp = New Class2(pertinentinfo)
    	Dim doThread As New Thread(AddressOf GetComp.setData)
        End Sub
        Public Sub New()
            ' This call is required by the designer.
            ' Add any initialization after the InitializeComponent() call.
        End Sub
    End Class
    Last edited by GremlinSA; May 30th, 2013 at 12:08 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.