问题描述
请指导我如何防止在DevExpress.XtraGrid.GridControl上自动添加新行。
Please guide me how to prevent new rows added automatically on DevExpress.XtraGrid.GridControl
我想控制何时添加新行,在我的情况下使用keydown事件(CTRL + I)进行此任务。但是如果我将焦点(光标指针)移动到最后一行的区域,则网格会自动添加新行,然后单击。
I want to control when new rows is added, in my case i'm using a keydown event (CTRL + I ) for this task. But the grid keep adding new rows automatically if i move the focus (cursor pointer) to the area right below to the last row and click.
GridControl.MainView是一个 BandedGridView ,其中包含数据源。
The GridControl.MainView is a BandedGridView, which contains the datasource.
推荐答案
您可以处理ValidateRow事件。如果您设置 e.Valid = false
,则不会添加新行。所以检查你的对象是空的还是无效的,只要输入需要的值就可以免费送行。
You can handle the ValidateRow event. If you set e.Valid = false
you wont add a new row. So check if your object is empty or invalid and just if the needed values are typed you give the row free.
private void grvMyView_ValidateRow(object sender, ValidateRowEventArgs e)
{
if (grvMyView.IsNewItemRow(e.RowHandle))
{
MyObject obj = grvMyView.GetRow(e.RowHandle) as MyObject;
e.Valid = obj.IsValid();
}
}
这篇关于Devexpress GridControl:防止新行自动添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!