删除最后一行dataGridView的最后一行 [英] Removing last empty row of dataGridView
问题描述
谢谢。
选择空行:
我得到这个:
结论:经过多次尝试找到解决方案,我决定使用datagridview和两个按钮创建UI控件(添加行和删除行)。在这一点上,我停止了按计划进行的尝试,但我仍然很高兴知道解决方案。
你可以处理 RowValidating
事件以验证行是否为空。如果是,则取消事件和行将不被添加。
if(gridView [0,e.RowIndex] .Value = = null)
e.Cancel = true;
I have some empty datagridview which uses data source is List through BindingSource. Because AllowUserToAddRows = true, initially the datagridview has one empty row. When I just select this row and close the form then datagridview creates new empty object. Why it does it? How to prevent this? Thanks.
Selecting of empty row: And I get this:
Conclusion: After many attempts to find a solution I decided to create UI control with datagridview and two buttons (add row and delete row). At this point I stopped trying to do as planned, but I'd still be pleased to know solutions.
You can handle RowValidating
event to verify if row is empty. If so, then cancel event and row will not be added.
if (gridView[0, e.RowIndex].Value == null)
e.Cancel = true;
这篇关于删除最后一行dataGridView的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!