如何验证Lost Focus上的WPF Datagrid单元格以检查空值 [英] How to Validate WPF Datagrid Cell on Lost Focus to check null value
本文介绍了如何验证Lost Focus上的WPF Datagrid单元格以检查空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用WPF工具包:Datagrid并使用EDM作为其itemsource。
当我更改网格中的第一个单元格时,EDM设计器类给我一个错误。
它的属性被绑定到源。
它给了我一个错误=这个属性不能设置为空值。
I am using WPF toolkit:Datagrid and using EDM as its itemsource.
EDM designer class is giving me an error while I change the first cell in the grid.
It's property is getting binded to the source.
It is giving me an error = "This property cannot be set to a null value."
dgFinancialYear.Columns.Add(new Microsoft.Windows.Controls.DataGridTextColumn { Header = "Financial Year", Binding = new Binding { Path = new PropertyPath("FinancialYear"), ValidatesOnExceptions = true, ValidatesOnDataErrors = true, UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged, NotifyOnSourceUpdated = true, }, Width = 160 });
上面是网格列的代码,WPF工具包中没有任何单元格更改或单元格编辑结束事件:Datagrid
任何帮助都将受到高度赞赏。
Above is the code for the grid column and there is no any cell change or cell edit ending event in WPF toolkit:Datagrid
Any help will be highly appreciated.
推荐答案
private void dgFinancialYear_CellEditEnding(object Sender,DataGridCellEditEndingEventArgs e)
{
if(getCurrentCellValue((TextBox)e.EditingElement)=="")
{
e.Cancel=true;
}
}
private string getCurrentCellValue(TextBox txtCurCell)
{
return txtCurCell.Text;
}
这篇关于如何验证Lost Focus上的WPF Datagrid单元格以检查空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文