0

I'm trying to make a search inside a datagridview, looping through every cell and comparing 2 strings - SearchString and CellString.

I divide the work into four threads (by giving each thread a different quater of the rows to work with) that work in parallel. Threads CANNOT read one and the same cell at the same time, because they loop through different rows, so I don't think the error's there.

Each thread does the following:

   dim CellString as string
   For i As Integer = startrow To endrow

        For Each cell As DataGridViewCell In DataGridView.Rows(i).Cells

            CellString = cell.Value.ToString.ToLower ''Error appears here

            If cell.ColumnIndex <> 4 Then
                Select Case Compare(CellString, SearchString) ''complex function that compares 2 strings

                   ''....
                End Select
            End If
        Next
  Next

The error I get is :

BindingSource cannot be its own data source. Do not set the DataSource and DataMember properties to values that refer back to BindingSource.

I don't get why this happens because i don't mess with the BindingSource nor with the DataSource. Also I don't do any updates I only read every cell as a string.

I couldn't find any similar problem, so any help is appreciated !

1 Answers1

1

Without seeing your whole code, it is hard to answer the question exactly but everything points to the fact that you are trying to access some elements of your UI (which Datagridview is part of) from the threads that you are creating.

According to Microsoft, this is not legal:

By design, Windows Form or Control methods cannot be called on a thread other than the one that created the form or control

Check this article for more info. It helped me resolve the similar issue.

myroslav
  • 1,670
  • 1
  • 19
  • 40