修改单元格关联更新其它列的值,Dev GridView组件OnCellValueChanged事件实现
作者:作者不详  发布日期:2021/06/26 17:46:18
  修改单元格关联更新其它列的值,Dev GridView组件OnCellValueChanged事件实现

修改单元格关联更新其它列的值,Dev GridView组件OnCellValueChanged事件实现



DevExpress GridView单元格CellValueChanged事件详解,
参考采购订单,销售订单开发实例。


DevExpress GridView单元格CellValueChanged事件详解



GridView的CellValueChanged事件:当用户修改单元格的值时立即触发。



C/S开发框架参考代码:


C# Code:

gvDetail.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(OnCellValueChanged); //表格值改变

//来源:C/S框架网 | www.csframework.com | QQ:23404761



OnCellValueChanged事件:


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




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




通过此参数我们可以获取当前修改的列对象、资料行号以及单元格的值。




C/S框架网|原创精神.创造价值.打造精品


扫一扫加作者微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务



上一篇 下一篇