DevExpress GridView单元格CellValueChanged事件详解
DevExpress GridView单元格CellValueChanged事件详解
DevExpress GridView单元格CellValueChanged事件详解,
DevExpress GridView单元格CellValueChanged事件详解,
参考采购订单,销售订单开发实例。
GridView的CellValueChanged事件:当用户修改单元格的值时立即触发。
开发框架应用场景:
OnCellValueChanged事件:
OnCellValueChanged事件的CellValueChangedEventArgs参数:
通过此参数我们可以获取当前修改的列对象、资料行号以及单元格的值。
扫一扫加微信:
CellValueChangedEventHandler事件描述:Fires immediately after a cell's value has been changed.
C# Code:
//
// 摘要:
// Fires immediately after a cell's value has been changed.
[DevExpressXtraGridLocalizedDescriptionAttribute("ColumnViewCellValueChanged")]
[DXCategory("Property Changed")]
public event CellValueChangedEventHandler CellValueChanged;
// 摘要:
// Fires immediately after a cell's value has been changed.
[DevExpressXtraGridLocalizedDescriptionAttribute("ColumnViewCellValueChanged")]
[DXCategory("Property Changed")]
public event CellValueChangedEventHandler CellValueChanged;
开发框架应用场景:
开发企业管理系统比如ERP系统的采购订单,明细表通常有采购数量、单价、金额等字段。当用户修改数量或单价时,要自动计算金额。
金额字段是只读的,不可直接修改。
C/S开发框架参考代码:
C# Code:
gvDetail.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(OnCellValueChanged); //表格值改变
//来源:C/S框架网 | www.csframework.com | QQ:23404761
//来源:C/S框架网 | www.csframework.com | QQ:23404761
C# Code:
private void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
{
if ((e.Column == colD_Price) || (e.Column == colD_Quantity))
{
decimal price = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Price]);//单价
decimal quantity = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Quantity]);//数量
decimal amt = Math.Round(price * quantity, 2, MidpointRounding.ToEven);//金额=数量*单价
//计算本产品的采购金额
gvDetail.SetFocusedRowCellValue(colD_Amount, amt);
gvDetail.UpdateCurrentRow();//更新当前资料行
gvDetail.UpdateTotalSummary();//更新合计
//更新主表的合计金额
decimal totalAmt = ConvertEx.ToDecimal(colD_Amount.SummaryItem.SummaryValue);
this.SetEditorBindingValue(txtAmount, totalAmt, true);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
if ((e.Column == colD_Price) || (e.Column == colD_Quantity))
{
decimal price = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Price]);//单价
decimal quantity = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Quantity]);//数量
decimal amt = Math.Round(price * quantity, 2, MidpointRounding.ToEven);//金额=数量*单价
//计算本产品的采购金额
gvDetail.SetFocusedRowCellValue(colD_Amount, amt);
gvDetail.UpdateCurrentRow();//更新当前资料行
gvDetail.UpdateTotalSummary();//更新合计
//更新主表的合计金额
decimal totalAmt = ConvertEx.ToDecimal(colD_Amount.SummaryItem.SummaryValue);
this.SetEditorBindingValue(txtAmount, totalAmt, true);
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
OnCellValueChanged事件的CellValueChangedEventArgs参数:
C# Code:
public class CellValueChangedEventArgs : EventArgs
{
DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs.Column
DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs.Value
public CellValueChangedEventArgs(int rowHandle, GridColumn column, object value);
//
// 摘要:
// Gets the column that contains the processed cell.
public GridColumn Column { get; }
//
// 摘要:
// Gets the handle of the row that contains the processed cell.
public int RowHandle { get; }
//
// 摘要:
// Gets the current cell value.
public object Value { get; }
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs.Column
DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs.Value
public CellValueChangedEventArgs(int rowHandle, GridColumn column, object value);
//
// 摘要:
// Gets the column that contains the processed cell.
public GridColumn Column { get; }
//
// 摘要:
// Gets the handle of the row that contains the processed cell.
public int RowHandle { get; }
//
// 摘要:
// Gets the current cell value.
public object Value { get; }
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
通过此参数我们可以获取当前修改的列对象、资料行号以及单元格的值。
扫一扫加微信:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网