dataTable 绑定 DataGridView 后 用 dataRow.Delete() 方法删除 dataTable 表中数据 后
该行数据在 DataGridView 中为不可见。
但是 现在假设:
dataTable 有 5 行数据 在DataGridView 中 顺序显示 为
0,
1,
2,
3,
4
当 删除了额 数据行 2,后
在DataGridView 中 顺序显示 为
0,
1,
3,
4
此时 DataGridView 当前行 为 数据行 3,但 问题是 此时再调用dataRow.Delete() 删除时 不起作用!应该 此时dataTable 游标 还是指向 dataTable 的数据行2(数据行2 只是被做了删除标记 并没有被删除)在这种情况下,请问 如何移动 dataTable 的游标 让她 跟 DataGridView 显示时 的当前行 同步谢谢! 困惑好久了
该行数据在 DataGridView 中为不可见。
但是 现在假设:
dataTable 有 5 行数据 在DataGridView 中 顺序显示 为
0,
1,
2,
3,
4
当 删除了额 数据行 2,后
在DataGridView 中 顺序显示 为
0,
1,
3,
4
此时 DataGridView 当前行 为 数据行 3,但 问题是 此时再调用dataRow.Delete() 删除时 不起作用!应该 此时dataTable 游标 还是指向 dataTable 的数据行2(数据行2 只是被做了删除标记 并没有被删除)在这种情况下,请问 如何移动 dataTable 的游标 让她 跟 DataGridView 显示时 的当前行 同步谢谢! 困惑好久了
dataTable.Rows.RemoveAt(行号);
dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
private void dgView_CrtPeriod_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
(sender as DataGridView).Rows[e.RowIndex].ErrorText = null; DateTime startDate = (DateTime)(sender as DataGridView).Rows[e.RowIndex].Cells[this.ColStartDate.Index].Value; //// 此处 出现错误 错误提示 e.RowIndex threw an exception
// of type "System.NullReferenceException" 请问为什么 ?
{
dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
}
在删除最后一行数据时 DataGridView 也对 数据进行行 验证 所以就出错了
private void dgView_CrtPeriod_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
(sender as DataGridView).Rows[e.RowIndex].ErrorText = null; DateTime startDate = (DateTime)(sender as DataGridView).Rows[e.RowIndex].Cells[this.ColStartDate.Index].Value; //// 此处 出现错误 错误提示 e.RowIndex threw an exception
// of type "System.NullReferenceException" 请问为什么 ?