WinForm中DataGridView使用DataView的Sort排序后删除数据行数错误问题

DataView dv=new DataView(ds.Tables["student"]);

dv.RowFilter=" studentName like  ' 张% ' ";

dv.Sort=" studentNo desc ";

dataGridViewStudent.DataSource = dv

在删除按钮里面如果采用如下方式进行删除时,删除的内容并不是你选中的行,而是ds数据集中的行数据。

int rowIndex = dataGridViewStudent.SelectRows[0].Index;

ds.Tables["student"].Rows[rowIndex].Delete();  

adp.Update(ds, "grade");


应该采用dv[rowIndex].Delete();方式删除即可。

你可能感兴趣的:(WinForm)