Joe Pool

Joe Pool

  • 1.3k
  • 52
  • 997

Thread searching a DataGridView Control

Apr 29 2010 2:23 PM
As my people are entering data into a textbox, I want to bring the most relevant row of data into view on my DataGridView control.

I do this now, but I can't do it in a thread since it is part of the Form and not thread safe.

How can I search a DataGridView's data from within a thread?

Example:
int FindRow(string textBoxValue) {
  for (int i = 0; i < DataGridView1.Rows.Count; i++) {
    if (DataGridView1.Rows[i].Cells[x].Value.ToString() == textBoxValue) {
      return DataGridView1.Rows[i].Index;
    }
  }
  return 0;
}

The above is not thread safe, of course.

I don't want to pass the entire DataGridView object to a thread as a parameter because it can be rather large and our clerks enter data pretty fast!

Answers (4)