在 AddNewRecord 行中输入值后,单击 XamDataGrid 上该行外部的任意位置似乎会将该行添加到集合中。
如何防止鼠标单击向集合中添加新行。
请帮忙
最佳答案
在 AddNewRecord 外部单击会结束记录的编辑模式,如果有更改,则会在此时提交,这意味着添加了新记录。如果您希望仅允许在按 Enter 键时提交记录,而不是通过单击网格中的另一条记录,那么您可以使用以下逻辑将鼠标左键设置为已处理:
private bool editingAddNewRecord = false;
void XamDataGrid1_EditModeEnded(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndedEventArgs e)
{
this.editingAddNewRecord = false;
}
void XamDataGrid1_EditModeStarted(object sender, Infragistics.Windows.DataPresenter.Events.EditModeStartedEventArgs e)
{
this.editingAddNewRecord = e.Cell.Record.IsAddRecord;
}
void XamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (editingAddNewRecord)
{
DataRecordPresenter drp = Infragistics.Windows.Utilities.GetAncestorFromType(e.OriginalSource as DependencyObject, typeof(DataRecordPresenter), true) as DataRecordPresenter;
if (!(drp != null && drp.IsAddRecord))
{
e.Handled = true;
}
}
}
关于infragistics - 添加新记录 XamDataGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13592818/