一、前言

前提是 C1FlexGrid 中存在数据绑定列和自定义列(非数据绑定列),此时如果该行编辑后出现排他错误,自定义列也会出现验证结果的红色边框:

[C1] C1FlexGrid 排除非绑定列的验证效果

但是自定义列如果只是一些按钮操作,提示说明什么的,与前面绑定的数据并无关系,不想参与到前面的排他错误提示,也就是不想要这个红色边框,该如何处理?

二、实现

  1 using System.Collections.ObjectModel;
  2 using System.ComponentModel;
  3 
  4 namespace Validation
  5 {
  6     public class DataObject : IDataErrorInfo
  7     {
  8         public string Name { get; set; }
  9         public int Age { get; set; }
 10         public string Sex { get; set; }
 11         public string UpdateErrorMessage { get; set; }
 12 
 13         // property-level
 14         public string this[string propertyName]
 15         {
 16             get
 17             {
 18                 if (!string.IsNullOrEmpty(UpdateErrorMessage))
 19                 {
 20                     return UpdateErrorMessage;
 21                 }
 22                 if (propertyName == "Name" && string.IsNullOrWhiteSpace(Name))
 23                 {
 24                     return "Name is invalid!";
 25                 }
 26 
 27                 return string.Empty;
 28             }
 29         }
 30 
 31         // item-level
 32         string IDataErrorInfo.Error
 33         {
 34             get
 35             {
 36                 if (!string.IsNullOrEmpty(UpdateErrorMessage))
 37                 {
 38                     return UpdateErrorMessage;
 39                 }
 40 
 41                 return "";
 42             }
 43         }
 44 
 45 
 46         // 初始化数据源
 47         public static ObservableCollection<DataObject> InitDataSource()
 48         {
 49             ObservableCollection<DataObject> itemSource = new ObservableCollection<DataObject>();
 50             itemSource.Add(new DataObject() {
 51                 Name = "aa",
 52                 Age = 11,
 53                 Sex = "" });
 54             itemSource.Add(new DataObject() {
 55                 Name = "vv",
 56                 Age = 15,
 57                 Sex = "" });
 58             itemSource.Add(new DataObject() {
 59                 Name = "aa",
 60                 Age = 11,
 61                 Sex = "" });
 62             itemSource.Add(new DataObject() {
 63                 Name = "aa",
 64                 Age = 11,
 65                 Sex = "" });
 66             itemSource.Add(new DataObject() {
 67                 Name = "aa",
 68                 Age = 11,
 69                 Sex = "" });
 70             itemSource.Add(new DataObject() {
 71                 Name = "aa",
 72                 Age = 11,
 73                 Sex = "" });
 74             itemSource.Add(new DataObject() {
 75                 Name = "aa",
 76                 Age = 11,
 77                 Sex = "" });
 78 
 79             return itemSource;
 80         }
 81     }
 82 }
数据对象

相关文章:

  • 2021-12-01
  • 2022-12-23
  • 2021-05-23
  • 2021-05-07
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
猜你喜欢
  • 2021-06-17
  • 2021-06-18
  • 2022-12-23
  • 2021-12-19
  • 2021-07-06
  • 2021-11-27
  • 2021-07-09
相关资源
相似解决方案