Winforms Propertygrid中的validation
是否可以在Winforms Propertgrid控件中实现输入validation ? 例如,我如何validation/定义“必填字段”? 我可以使用错误提供程序吗? 是否可以使用RequiredAttribute (System.ComponentModel.DataAnnotations)?
注册OnValueChanged事件并在那里完成工作!
propertyGrid.PropertyValueChanged+= new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged ); private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { if (e.ChangedItem.Label == "???" && !IsValid((int)e.ChangedItem.Value) ) { // the entered value is wrong - show error message e.ChangedItem.PropertyDescriptor.SetValue( propertyGrid.SelectedObject, e.OldValue); MessageBox.Show("Wrong Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } private static bool IsValid( int inputData) { // logic here }
我希望这能帮助你解决问题!
上述就是C#学习教程:Winforms Propertygrid中的validation分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1004143.html