Hi all,

i want to add data manully to a dataGridView.but i get this exception.

ArgumentOutOfRangeException.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

PLZ help me to solve this.
this is my code.

int clicks=0;
private void button4_Click(object sender, EventArgs e)
        {
            
            dataGridView1.Rows[clicks].Cells["Author_Number"].Value = "Author "+(clicks+1).ToString();
            dataGridView1.Rows[clicks].Cells["First_name"].Value = "fname";
            dataGridView1.Rows[clicks].Cells["Last_name"].Value = "lname";
            clicks++;
        }

You have to add rows as well (every loop):

int clicks = 0;
        private void button4_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Add();
            dataGridView1.Rows[clicks].Cells["Author_Number"].Value = "Author " + (clicks + 1).ToString();
            dataGridView1.Rows[clicks].Cells["First_name"].Value = "fname";
            dataGridView1.Rows[clicks].Cells["Last_name"].Value = "lname";
            clicks++;
        }
This question has already been answered. Start a new discussion instead.