如果只是判断值超出范围,可以利用Cell.Validators添加一个RangeValidator来实现。
如果想判断只输入了部分数值,这个需要访问InputMan GcDateTime上的属性精确判断,参考代码如下:
- private object oldValue;
- void gcMultiRow1_CellBeginEdit(object sender, CellBeginEditEventArgs e)
- {
- if (e.Scope == CellScope.Row)
- {
- this.oldValue = this.gcMultiRow1[e.RowIndex, e.CellIndex].FormattedValue;
- }
- }
- void gcMultiRow1_CellValidating(object sender, CellValidatingEventArgs e)
- {
- GrapeCity.Win.Editors.GcDateTime gcDate = this.gcMultiRow1.EditingControl as GrapeCity.Win.Editors.GcDateTime;
- if (gcDate == null)
- {
- return;
- }
- if (gcDate.Value.HasValue &&
- !(gcDate.Value.Value >= new DateTime(2015, 1, 1) && gcDate.Value.Value <= new DateTime(2015, 12, 31)))
- {
- if (oldValue is DateTime)
- {
- gcDate.Value = (DateTime)oldValue;
- }
- }
- if (gcDate.InputStatus == GrapeCity.Win.Editors.InputStatus.Part)
- {
- if (oldValue is DateTime)
- {
- gcDate.Value = (DateTime)oldValue;
- }
- }
- }
复制代码 |