C#如何从datagridview中删除项目(当前项目无法从列表中删除,因为没有当前项目) [英] C# how to delete item from datagridview (current item cannot be removed from the list because there is no current item)
本文介绍了C#如何从datagridview中删除项目(当前项目无法从列表中删除,因为没有当前项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在datagridview中有拒绝按钮喜欢这个 [ ^ ]
当我选择一行并点击时那个按钮,那行必须从datagridview中删除,但出了点问题,它给了我错误。当前项目无法从列表中删除,因为没有当前项目。问题是什么?
我尝试过:
I have Reject button in datagridview Like this[^]
When i select anr row and click on that button, that row must remove from datagridview,but something went wrong,it gives me error` Current item cannot be removed from the list because there is no current item.What's the problem?
What I have tried:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView2.Columns[e.ColumnIndex].Name == "Reject")
{
if(MessageBox.Show("Are you sure that you want to reject this bid?","Message",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
creditRequestsBindingSource.RemoveCurrent();
}
}
推荐答案
问题是当你单击一行中的按钮时,直到处理完按钮点击后才选择该行。
如果是我,我会在网格外部创建一个按钮,只在选择了一个网格行。
The problem is when you click a button in a row, the row isn't selected until after the button click is handled.
If it were me, I'd create a button external of the grid and only enable it when a grid row is selected.
这篇关于C#如何从datagridview中删除项目(当前项目无法从列表中删除,因为没有当前项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文