首页 > 代码库 > gridControl单元格的值随另一个单元格值的改变而改变

gridControl单元格的值随另一个单元格值的改变而改变

private void grvDetail_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (grvDetail.RowCount > 0 && e.RowHandle >= 0)
{

if (grvDetail.FocusedColumn.FieldName == "partQty" || grvDetail.FocusedColumn.FieldName == "partQtyM")
{
try
{
int handle = e.RowHandle;
decimal i = 0;
decimal qty=0;
decimal qtym=1;
decimal moty=0;
if (decimal.TryParse(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colpartQty).ToString(), out i))
{
qty = Convert.ToDecimal(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colpartQty).ToString());
}
if (decimal.TryParse(txtMoQty.Text, out i))
{
moty = Convert.ToDecimal(txtMoQty.Text);
}
decimal j = 1;
if (decimal.TryParse(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colpartQtyM).ToString(), out j))
{
qtym = Convert.ToDecimal(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colpartQtyM).ToString());
}

decimal sumqty = qty * moty / qtym;
if (sumqty != Convert.ToDecimal(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colSumQty).ToString()))
{
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colSumQty, sumqty);
}//此处判断很重要

}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
}
}

gridControl单元格的值随另一个单元格值的改变而改变