c# – Popular datagrid com threading

Question:

I'm contracting a Windows Form application. I'm not able to populate my datagrid with a thread , the following error appears:

"Invalid cross-thread operation: datagrid control accessed from a thread that is not the one in which it was created

Answer:

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

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

What you can do is 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;
     }
}));
Scroll to Top
AllEscort