C# DataGridView 捕获已删除的行
1.
我正在使用 DataGridView,它绑定到数据集。 还有一个绑定导航器。
当用户通过单击“bindingNavigatorDeleteItem”按钮删除一行时,我试图删除该行。
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
int crow = gridEventType.CurrentCell.RowIndex;
但它会在删除选定行后返回新选定的行。 所以,如果我有两行 0 1 2 我删除 2
只乌鸦是 1,而不是 2。
我在这里遗漏了什么吗?
2.我如何知道datagridview中的某些行是否被修改?
谢谢,
1.
I am using a DataGridView, which is bound to a dataset.
There is a bindingNavigator as well.
when a user deletes a row by clicking "bindingNavigatorDeleteItem" button, I am trying to get the row being deleted.
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
int crow = gridEventType.CurrentCell.RowIndex;
but it returns the newly selected row AFTER deletion of a selected row.
so, If I have two rows
0
1
2
and I delete 2
crow is 1, not 2.
Am I missing something here?
2. How do I know whether certain rows are modified in datagridview?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 datagridview.UserDeletingRow 事件获取已删除的行对象。
Use the datagridview.UserDeletingRow event to get the deleted row object.
您应该使用
DataGridViewCellEventArgs
。对于第二点,有一个 CellValueChangedEvent。
You should be using the
DataGridViewCellEventArgs
.For your second point, there's a CellValueChangedEvent.
对于我的问题#1。
通过
获取当前行号
int cRow = gridEventType.CurrentCell.RowIndex;
从绑定源中删除当前项
BindingNavigator.BindingSource.RemoveCurrent();
For my Question #1.
get current row number by
int cRow = gridEventType.CurrentCell.RowIndex;
delete the current item from bindingsource
BindingNavigator.BindingSource.RemoveCurrent();
尝试使用 UserDeletingRow 作为删除行的事件处理程序,在该方法中您可以获得行索引,如下所示:
Try to use
UserDeletingRow
as an event handler for deleting a row, and inside this method you can get the row index and as below: