Question help with error Dialog in datagridview

just369

Member
Joined
May 12, 2010
Messages
17
Programming Experience
Beginner
:confused:Hi i got this error in my code when the program runs i dont know what am i doing wrong


Datagridview Default Error Dialog
The Following exception ocurred in the datagridview
System.InvalidOperationException: Binding Source cannot be its own data source........
heres a pic of the message
error 10.jpg


heres my code
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.BackgroundWorker1.RunWorkerAsync(DataGridView1)
     
        If DataGridView1.Visible = False Then
            DataGridView1.Visible = True
            Button2.Visible = True
            DataGridView2.Visible = False
            Botonip.Visible = False
        End If

        PictureBox1.Visible = True
        DataGridView2.Rows.Clear()
        Button1.Enabled = False

    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

        Dim hello As String
        Dim sum As Integer

        For sum = 0 To DataGridView1.Rows.Count - 1
            hello = DataGridView1.Rows.Item(sum).Cells.Item(1).Value  ''this checks the ip of row 2 cell 2
            Try
                If My.Computer.Network.Ping(hello, 500) Then ''this will ping the ip address and return true or false
                    DataGridView1.Rows.Item(sum).Cells.Item(2).Value = "True" '' this checks or not the checkbox for true or false

                    Try
                        DataGridView1.Rows.Item(sum).Cells.Item(3).Value = System.Net.Dns.GetHostEntry(hello).HostName ''this gets the host name of a computer
                    Catch ex As Exception
                        DataGridView1.Rows.Item(sum).Cells.Item(3).Value = "Error en Host"
                    End Try

                    If DataGridView1.Rows.Item(sum).Cells.Item(3).Value = hello Then
                        Dim Myhostname As String = GetCpname(hello)
                        Dim hostnewname As String() = Myhostname.Split(" "c, "<"c)
                        DataGridView1.Rows.Item(sum).Cells.Item(3).Value = (hostnewname(0))
                    End If

                    Dim Mymac As String = GetMACAddress(hello)
                    Dim MyChar As Char() = {"M"c, "A"c, "C"c, "a"c, "d"c, "d"c, "r"c, "e"c, "e"c, "s"c, " "c, "="c}
                    Dim mynewmac As String = Mymac.TrimStart(MyChar)
                    DataGridView1.Rows.Item(sum).Cells.Item(4).Value = mynewmac

                Else
                    DataGridView1.Rows.Item(sum).Cells.Item(2).Value = "false"
                    DataGridView1.Rows.Item(sum).Cells.Item(3).Value = ""
                    DataGridView1.Rows.Item(sum).Cells.Item(4).Value = ""
                End If
            Catch ex As Exception
                Debug.Write(ex.Message)
            End Try
        Next
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        Button1.Enabled = True
        DataGridView1.AutoResizeColumn(1, DataGridViewAutoSizeColumnMode.AllCells)
        DataGridView1.AutoResizeColumn(2, DataGridViewAutoSizeColumnMode.AllCells)
        DataGridView1.AutoResizeColumn(3, DataGridViewAutoSizeColumnMode.AllCells)
        DataGridView1.AutoResizeColumn(4, DataGridViewAutoSizeColumnMode.AllCells)
        MsgBox("El Programa a Terminado de Buscar Computadoras en Linea")
        PictureBox1.Visible = False
    End Sub


thank you
 
First things first, you should absolutely not be touching your grid in the DoWork event handler. DoWork is raised in a background thread and you should only be touching the UI on the UI thread.

As for the issue, it sounds like you've messed up your bindings. What are the DataSource and DataMember property values of the BindingSource and the DataGridView?
 
for the datagrid
datasource is IPSBindingSource
and datamember is nothing

for the ipbindingsource is
datasource is ipdataset
and datamember is ips
 
Back
Top