关于DevExpressGridView事件
//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();
}
}gridview不显示
}
}
验证编辑器事件(单列)
//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();
}
}
}
}
验证编辑器事件(多列)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。