Popular datagrid with threading

3

I'm contracting a Windows Form application. I am not getting my datagrid popular with a threading , the following error appears:

  

"Invalid thread operation: datagrid control accessed from a thread in the thread it was created on.

    
asked by anonymous 14.08.2015 / 03:35

1 answer

1

A UI (control) screen element in Winforms and WPF does not allow access by other threads or multiple threads.

The UI element can only be accessed by the thread that was created on it.

What you can do is to use delegates ...

Invoke(new Action(() =>
{
     if (dataGridView1.CurrentCell.RowIndex < dataGridView1.RowCount )
     {
          dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Selected = false;
          dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex + 1].Selected = true;
     }
}));
    
14.08.2015 / 06:35