且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从C#中的Datagrid和数据库中删除选定的行

更新时间:2023-12-05 10:23:40

我相信line i = dataGridView1.SelectedCells [0] .RowIndex;抛出异常。

而不是尝试使用

I believe the line i = dataGridView1.SelectedCells[0].RowIndex; is throwing the exception.
instead try using
int i = datagridView1.CurrentCell.RowIndex;





或者你可以使用

dataGridView1.SelectedRows [0] .Cells [0 ]而不是dataGridView1.SelectedRows [i] .Cells [0]



or you can use
dataGridView1.SelectedRows[0].Cells[0] instead of dataGridView1.SelectedRows[i].Cells[0]