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
  • Can you not perform the searches on the datasource itself instead of the DGV? Commented Aug 9, 2013 at 17:22

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.