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單元格的值隨另一個單元格值的改變而改變