DevExpress GridView单元格CellValueChanged事件详解


  DevExpress GridView单元格CellValueChanged事件详解DevExpress GridView单元格CellValueChanged事件详解


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


DevExpress GridView单元格CellValueChanged事件详解



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


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;




开发框架应用场景:


开发企业管理系统比如ERP系统的采购订单,明细表通常有采购数量、单价、金额等字段。当用户修改数量或单价时,要自动计算金额。

金额字段是只读的,不可直接修改。



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框架网|原创作品.质量保障.竭诚为您服务


版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:删除用户前逻辑判断,检查当前用户是否关联业务数据或创建业务数据
下一篇:C/S框架主程序调用版本自动升级程序(CSFrameworkV5.AutoUpgrader)VersionCheckNEW类
评论列表

发表评论

评论内容
昵称:
关联文章

DevExpress GridView单元CellValueChanged事件详解
修改单元关联更新其它列的值,Dev GridView组件OnCellValueChanged事件实现
C# GridView 自定义单元的背景色
DevExpress GridView设置单元网格线颜色|C/S框架网
DevExpress GridView表格CustomUnboundColumnData事件异步加载图片
GridControl/GridView 单元的值输入非法自定义错误提示文本
DevExpress GridControl实现右键弹出菜单复制单元
GridView不能编辑单元的值受3个参数影响
DevExpress GridView 表格内嵌ButtonEdit按钮列图片按钮及Click事件
表格GridView.CustomDrawEmptyForeground事件显示没有查询到数据
C# DataGridView 自动给新增记录当前单元赋值
Dev表格列的勾选框无效,单元不可编辑,Editable与ReadOnly区别
解决方案:FastReport.NET导出Excel文件单元的数据空白
ButtonStateChanged事件详解 - 当按钮状态改变时触发的事件
DevExpress GridView表格记录位置调整,实现DataRow记录排序
C# DataGridView组件自动添加弹出菜单(ContextMenuStrip)复制单元的值
DevExpress换肤详解
C# Dev GridView表格的CustomUnboundColumnData事件异步加载图片类AsynDownImage
C#深入剖析事件(C# Event详解)
解决:DevExpress.GridControl.GridView表格导出乱码