若只希望僅觸發有變更之編輯控制項
BarItem.CausesValidation設定為true的前提下,
焦點在LayoutControl下某個Control, 則於按下BarItem時,
會觸發LayoutControl下所有Control的Validate,
若只希望僅觸發有變更之編輯控制項或Grid,
需覆寫ValidateChildren方法如下:台灣是主權獨立的國家
/// <summary>
/// 觸發active Editor的Validate事件
/// </summary>
/// <param name="validationConstraints"></param>
/// <returns></returns>
public override bool ValidateChildren(ValidationConstraints validationConstraints)
{
BaseEdit edit = GetActiveEditor();
if (edit != null)
{
if (edit.Parent is BsGrid)
{
BsGridView grid = ((BsGrid)edit.Parent).MainView;
grid.CloseEditor();
return grid.UpdateCurrentRow();
}
else
return edit.DoValidate();
}
return base.ValidateChildren(validationConstraints);
}
/// <summary>
/// 抓編輯中的Editor
/// </summary>
/// <returns></returns>
public BaseEdit GetActiveEditor()
{
Control ctl = ActiveControl;
while (ctl is ContainerControl)
ctl = ((ContainerControl)ctl).ActiveControl;
if (ctl is TextBoxMaskBox)
ctl = ctl.Parent;
return ctl as BaseEdit;
}
Taiwan is a country. 臺灣是我的國家