• 关于DevExpress GridView事件


    //RowCellStyle 行单元格样式事件
    //用于设置行单元格样式
    //这里举例 如果状态为0则白背景色改为蓝绿色
     
    if(e.RowHanle>=0)//当前视图的所有行
     {
         DataRow dr =this.view.GetRow(e.RowHanle);//获取所有行的数据
        if(dr==null) return;
         if(dr["AGE"]==0) 
         {
               e.Appearance.Backcolor=Color.YellowGreen;
         }       
     }
     //ValidatingEditor 验证编辑器事件   
     //验证view中某一列的值不能相同 
     //例:用户编号不能相同 USER_CODE
     private void viewUser_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
             {
                 //如果当前焦点列为用户编码列USER_CODE 
                 if (this.viewUser.FocusedColumn == this.viewUser.Columns[DE.GmUser.USER_CODE])
                 {
                     //e.Value当前列的值
                     if (e.Value == null || string.IsNullOrEmpty(e.Value.ToString())) return;
     
                     string usrCode = e.Value.ToString();
                     int currowHandler = this.viewUser.FocusedRowHandle;//当前焦点行的行号
                     int rowHandler = this.viewUser.LocateByValue(0, this.viewUser.FocusedColumn, usrCode);//从第一行开始查找该列相同的userCode,返回行号。view.(从哪里开始查找,列名,要查找的值)
     
                     if (rowHandler > -1)
                     {
                         if (rowHandler != currowHandler)
                         {
                             if (this.viewUser.FocusedValue != null)
                             {
                                 //提示信息:用户编号不能重复
                             }
                             e.Valid = false;//提示单元格的值无效 单元格会出现一个红色的×
                             this.viewUser.HideEditor();//隐藏编辑器,放弃次单元格所做的更改
                             this.viewUser.ShowEditor();//显示编辑器
                         }
     
                     }
                     else
                     {
                         rowHandler = this.viewUser.LocateByValue(this.viewUser.RowCount - 1, this.viewUser.FocusedColumn, usrCode);//反过来查找
     
                         if (rowHandler > -1 && rowHandler != currowHandler)
                         {
                             if (this.viewUser.FocusedValue != null)
                             {
                                 //提示信息:用户编号不能重复
                             }
                             e.Valid = false;
                             this.viewUser.HideEditor();
                             this.viewUser.ShowEditor();
                         }
                     }
                 }
     
             }
     
    验证编辑器事件(单列)
     //ValidatingEditor 验证编辑器事件   
     //验证view中某多列的值不能相同 
     
     private void viewOrgTarget_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
             {
                 if (this.viewOrgTarget.FocusedColumn == this.viewOrgTarget.Columns[DE.BmOrgTarget.OPER_DATE])
                 {
                     int intHandle = this.viewOrgTarget.FocusedRowHandle;
                     this.viewOrgTarget.FocusedRowHandle = -1;
                     this.viewOrgTarget.FocusedRowHandle = intHandle;
     
                     if (e.Value == null || string.IsNullOrEmpty(e.Value.ToString())) return;
     
                     DataRow drCurrent = this.viewOrgTarget.GetFocusedDataRow();
     
                     string strBrandId = TWays.Utils.ToString(drCurrent[DE.BmOrgTarget.BRAND_ID]);
                     string strBranchId = TWays.Utils.ToString(drCurrent[DE.BmOrgTarget.BRANCH_ID]);
                     string strCateId = TWays.Utils.ToString(drCurrent[DE.BmOrgTarget.CATE_ID]);
                     string strOrgType = TWays.Utils.ToString(drCurrent[DE.BmOrgTarget.ORG_TYPE]);
                     string strOperDate = e.Value.ToString();
                     if (string.IsNullOrEmpty(strBrandId))
                     {
                          //提示信息
                         e.Valid = false;
                         this.viewOrgTarget.HideEditor();
                         this.viewOrgTarget.ShowEditor();
                     }
                     else if (string.IsNullOrEmpty(strBranchId))
                     {
                          //提示信息
                         e.Valid = false;
                         this.viewOrgTarget.HideEditor();
                         this.viewOrgTarget.ShowEditor();
                     }
                     else if (string.IsNullOrEmpty(strCateId))
                     {
                          //提示信息
                         e.Valid = false;
                         this.viewOrgTarget.HideEditor();
                         this.viewOrgTarget.ShowEditor();
                     }
                     else if (string.IsNullOrEmpty(strOrgType))
                     {
                          //提示信息
                         e.Valid = false;
                         this.viewOrgTarget.HideEditor();
                         this.viewOrgTarget.ShowEditor();
                     }
                     else if (!string.IsNullOrEmpty(strOperDate))
                     {
                         int iRowCount = 0;
     
                         for (int i = 0; i < this.viewOrgTarget.RowCount; i++)
                         {
                             DataRow dr = this.viewOrgTarget.GetDataRow(i);
                             if (TWays.Utils.ToString(dr[DE.BmOrgTarget.BRAND_ID]) == strBrandId &&
                                 TWays.Utils.ToString(dr[DE.BmOrgTarget.BRANCH_ID]) == strBranchId &&
                                 TWays.Utils.ToString(dr[DE.BmOrgTarget.CATE_ID]) == strCateId &&
                                 TWays.Utils.ToString(dr[DE.BmOrgTarget.ORG_TYPE]) == strOrgType &&
                                 TWays.Utils.ToString(dr[DE.BmOrgTarget.OPER_DATE]) == strOperDate)
                             {
                                 iRowCount++;
                             }
                         }
                         if (iRowCount > 0)
                         {
                              //提示信息
                             viewOrgTarget.SetFocusedRowCellValue(colShowOperDate, null);
                             e.Valid = false;
                             this.viewOrgTarget.HideEditor();
                             this.viewOrgTarget.ShowEditor();
                         }
                     }
                 }
             }
    验证编辑器事件(多列)
  • 相关阅读:
    java图书管理系统界面版本+mysql数据库
    java数组实现的超市管理系统(控制台)
    Action<T>和Func<T>委托事例
    简单的委托示例
    使用静态方法CreateInstance()创建数组
    Span复习
    与预定义类型的用户类型强制转换
    实现自定义的索引运算符
    比较运算符的重载
    算术运算符的重载
  • 原文地址:https://www.cnblogs.com/Swaggy-yyq/p/12066446.html
Copyright © 2020-2023  润新知