2
Reply

Datagridview delete

Ask a question
diane falzon

diane falzon

14 years ago
2.9k
1
Hi i have a data table and is used like ths to add data todatagrid view (dgv) dt2 is the datatable.

DataGridViewRow row = dgv.SelectedRows[0];
            string a = row.Cells[0].Value.ToString();
            string b = row.Cells[1].Value.ToString();
            dt2.Rows.Add(a, b);
            dgvBill.DataSource = dt2;

Now when i am trying to delete from the datagridview the following error is occuring: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index.
the thing is that on the datagrid i have values so i am not sure why this is happining :/


DataGridViewRow row = dgv.SelectedRows[0];
            int a = row.Cells[0].RowIndex;
            dgvBill.Rows.RemoveAt(a);
            dgvBill.Refresh();

Answers (2)