private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Columns.Add("Autonumber", "Autonumber");
dataGridView1.Columns.Add("Name", "Name");
dataGridView1.Columns.Add("Address", "Address");
for (int i = 0; i < 4; i++)
{
DataGridViewRow dr = new DataGridViewRow();
dr.CreateCells(dataGridView1,new object[] {(i+1), "Shahan" + (i+1),"fdsfasfds"});
dataGridView1.Rows.Add(dr);
}
}
private void button2_Click(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(2); //to remove 3rd record; 3-1 = 2 , because index is zero-based
for (int i = 2; i < 4-1; i++) // 4-1, because 1 row has been deleted.
dataGridView1.Rows[i].Cells[0].Value = ((int)dataGridView1.Rows[i].Cells[0].Value) - 1;
}
|