gridControl 中CellValueChanged,ShowingEditor,CustomDrawCell的用法

private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
int hand = e.RowHandle;
if (hand >= 0)
{
if (e.Column.FieldName == "OneV")
{
string obj =gridView1.GetRowCellValue(hand, "Obj").ToString();
if (obj == "高压" || obj == "低压")
{
e.Appearance.BackColor = Color.Red;
}

              }
          }

    }

private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
if (gridView1.GetDataRow(e.RowHandle) == null)
return;
if (e.Column.FieldName == "未完成数量" || e.Column.FieldName == "入库未完成数量")
{
int WeiWangChengShu = this.gridView1.GetRowCellValue(e.RowHandle, "未完成数量").ToString() == "" ? 0 : int.Parse(this.gridView1.GetRowCellValue(e.RowHandle, "未完成数量").ToString());
int RukuWeiWangChengShu = this.gridView1.GetRowCellValue(e.RowHandle, "入库未完成数量").ToString() == "" ? 0 : int.Parse(this.gridView1.GetRowCellValue(e.RowHandle, "入库未完成数量").ToString());
if (WeiWangChengShu > 0 || RukuWeiWangChengShu > 0)
{
this.gridView1.SetRowCellValue(e.RowHandle, "进度跟进", "未完成");
}
}
}

private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
{
int thisIndex = this.gridView1.FocusedRowHandle;
if (thisIndex < 0)
{
return;
}
string shengChangType = this.gridView1.GetRowCellValue(thisIndex, "生产类型").ToString();
if (shengChangType != "包装")
{
if (this.gridView1.FocusedColumn.FieldName == "未完成数量" || this.gridView1.FocusedColumn.FieldName == "入库未完成数量")
{
e.Cancel = true;
}
}
}

private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (this.gridView1.FocusedColumn == e.Column)
{
if (e.Column == this.未完成数量 || e.Column == this.入库未完成数量)
{
//String strUnitNum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "未完成数量").ToString();
//String strRukuUnitNum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "入库未完成数量").ToString();//入库未完成数量
int strnum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "未完成数量").ToString()==""?0:int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "未完成数量").ToString());
int strRukuNum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "入库未完成数量").ToString() == "" ? 0 :int.Parse( gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "入库未完成数量").ToString());
//if(int.TryParse(strUnitNum,out strnum))
//{
// if (int.TryParse(strRukuUnitNum,out strRukuNum))
// {
//生产类型=‘包装‘的时候 ;输入的未完成数量/入库未完成数量 不允许大于 任务数;当生产类型<>‘包装’的时候 未完成数量/入库未完成数量 不允许编辑
if (gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "生产类型").ToString() == "包装")
{
int tasknum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "任务数").ToString() == "" ? 0 : int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "任务数").ToString());
if (strnum > tasknum || strRukuNum > tasknum)
{
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "未完成数量", "0");
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "入库未完成数量", "0");
return;
}
}

                        if (strnum > 0 || strRukuNum>0)
                        {
                            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "进度跟进", "未完成");
                        }
                        else
                        {
                            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "进度跟进", "");
                        }
                //    }
                //}
            }
        }
    }
原文地址:https://www.cnblogs.com/VictorBlog/p/5652279.html