I have a Windows form which is taking forever to load data into my datagridview.
I keep getting the error in this line:
    dataGridView1.Rows.Add(row);
Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on.
Here is my code:
    public List<string> _checked = new List<string>();
    private void getBarcodProperty()
    {                
        string query = "select Name from RfidUnic where Barcode = @barcode";
        while (true)
        {
            while (_checked.Count > 0)
            {
                SQLiteCommand cmd = new SQLiteCommand(query, sqliteConnection);
                cmd.Parameters.AddWithValue("@barcode", _checked[0]);
                sqliteConnection.Open();
                SQLiteDataReader da = cmd.ExecuteReader();
                if (da.Read())
                {
                    if (!da.IsDBNull(0))
                    {
                        string[] row = new string[] { da[0].ToString(), "1", _checked[0] };
                        dataGridView1.Rows.Add(row);
                        _checked.RemoveAt(0);
                    }
                }
                else
                {
                    string[] row = new string[] { "empty", "1", _checked[0] };
                    dataGridView1.Rows.Add(row);
                    _checked.RemoveAt(0);
                }
                sqliteConnection.Close();
            }
        }
    }
Please show me where I am going wrong
Thanks
 
     
     
     
    