//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();
}
}
}
}
验证编辑器事件(单列)