i have two dataGridViews in my windows form and for each gridview buttons to edit the content of the cell. however when i start my application i always get a System.NullReferenceException when i don't click on a row in the view first
The row is selected and blue after i started the application: selected row
I set the following in my load method:
            dataGridView1.Rows[0].Selected = true;
            dataGridView2.Rows[0].Selected = true;
The second DatagridView works fine. I don't know why...
That is my code for one button:
private void button2_Click(object sender, EventArgs e)
    {
        if (dataGridView1.SelectedRows.Count > 0)
        {
            int _selectedArticle_ID, _selectedArticle_ArtNr;
            string _selectedArticle_Artikel, _selectedArticle_Barcode;
            decimal _selectedArticle_einkaufsPreis, _selectedArticle_verkaufsPreis;
            _selectedArticle_ID = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value);
            _selectedArticle_ArtNr = Convert.ToInt32(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1].Value);
            _selectedArticle_Artikel = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[2].Value.ToString();
            _selectedArticle_einkaufsPreis = Convert.ToDecimal(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[3].Value);
            _selectedArticle_verkaufsPreis = Convert.ToDecimal(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[4].Value);
            _selectedArticle_Barcode = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[5].Value.ToString();
            f3 = new Form3(); // (_selectedArticle_ID, _selectedArticle_Anz, _selectedArticle_ArtNr, _selectedArticle_Artikel, _selectedArticle_Preis, _selectedArticle_Barcode, this);
            f3.Show();
        }
    }
 
    