没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:龚雪|2024-10-29 10:36:09.650|阅读 26 次
概述:本文主要介绍如何使用DevExpress WinForms的Data Grid组件创建未绑定列,欢迎下载最新版组件体验!
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
本教程将介绍:
P.S:DevExpress WinForms拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!
获取DevExpress WinForms v24.1正式版下载
DevExpress技术交流群10:532598169 欢迎一起进群讨论
一个与Northwind数据库的“Order Details”表绑定的数据网格应用程序。
1. 打开DevExpress WinForms Data Grid的智能标记,单击Add Column来创建列。
2. 选择此列并设置其属性为唯一的字符串:“DiscountAmount”。
3. 将列的属性设置为有效的数据类型。在本教程中,使用System.Decimal值。
1. 使用 属性:单击省略号按钮打开Expression Editor(表达式编辑器)。
2. 创建一个简单表达式,乘以三个字段:“Quantity”, “Unit Price”, “Discount”。
3. 将属性设置为false来使该列只读。
TIP:将列的设置为,将设置为c2,来将列值格式化为货币。
将列的属性设置为true,来允许用户在运行时修改未绑定列的表达式。
用户可以在运行时从列的上下文菜单调用表达式编辑器来更改表达式。
1. 创建另一个列,设置为Total,为System.Decimal。
2. 选择“gridView1”,并在属性面板的“Events”页面上订阅事件。
注意:事件在每次即将显示列值时和修改列单元格后(当需要发布数据时)触发。
3. 如果e.IsGetData事件参数为true,则使用方法检索Quantity、UnitPrice和Discount列的值。计算未绑定列的值,并将其分配给e.Value事件参数。
C#
void gridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { GridView view = sender as GridView; if(view == null) return; int rowIndex = e.ListSourceRowIndex; decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "UnitPrice")); decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Quantity")); decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Discount")); if (e.Column.FieldName != "Total") return; if (e.IsGetData) e.Value = unitPrice * quantity * (1 - discount); }
VB.NET
Private Sub gridView_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Dim view As GridView = TryCast(sender, GridView) If view Is Nothing Then Return End If Dim rowIndex As Integer = e.ListSourceRowIndex Dim unitPrice As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "UnitPrice")) Dim quantity As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Quantity")) Dim discount As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Discount")) If e.Column.FieldName <> "Total" Then Return End If If e.IsGetData Then e.Value = unitPrice * quantity * (1 - discount) End If End Sub
在编辑时,需要在未绑定列中保存更改。为此,您可以使用事件。
下面的代码将Total列单元格中的更改保存到一个字典中,e.IsSetData事件参数指示未绑定列中的单元格值是否被修改。
C#
Dictionary<int, decimal> customTotals = new Dictionary<int, decimal>(); private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { GridView view = sender as GridView; if(view == null) return; int rowIndex = e.ListSourceRowIndex; decimal unitPrice = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "UnitPrice")); decimal quantity = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Quantity")); decimal discount = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Discount")); if (e.Column.FieldName != "Total") return; if (e.IsGetData) { if (!customTotals.ContainsKey(rowIndex)) customTotals.Add(rowIndex, unitPrice * quantity * (1 - discount)); e.Value = customTotals[rowIndex]; } if (e.IsSetData) { customTotals[rowIndex] = Convert.ToDecimal(e.Value); } }
VB.NET
Private customTotals As New Dictionary(Of Integer, Decimal)() Private Sub gridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Dim view As GridView = TryCast(sender, GridView) If view Is Nothing Then Return End If Dim rowIndex As Integer = e.ListSourceRowIndex Dim unitPrice As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "UnitPrice")) Dim quantity As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Quantity")) Dim discount As Decimal = Convert.ToDecimal(view.GetListSourceRowCellValue(rowIndex, "Discount")) If e.Column.FieldName <> "Total" Then Return End If If e.IsGetData Then If Not customTotals.ContainsKey(rowIndex) Then customTotals.Add(rowIndex, unitPrice * quantity * (1 - discount)) End If e.Value = customTotals(rowIndex) End If If e.IsSetData Then customTotals(rowIndex) = Convert.ToDecimal(e.Value) End If End Sub
更多产品资讯及授权,欢迎“”!
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
文章转载自:慧都网FastReport .NET 的主要功能之一是能够将多份报告合并为一份。当您需要合并来自不同来源的数据或以更方便的格式呈现信息时,此功能非常有用。在本文中,我们将讨论如何在 FastReport .NET 中将多份报告合并为一份。
本文将手把手教你如何用VMProtect对这一关键函数进行虚拟化保护,大幅提升代码安全性,让逆向工程攻击者无从下手!
在 PDF 文档中添加页眉和页脚有助于保持一致的版式和专业的外观。本文将介绍如何使用 Spire.PDF for Java,通过 Java 在现有的 PDF 文档中添加页眉和页脚,并提供详细的步骤和代码示例。
对于开发人员来说,由于自动化和定制化,通常首选使用编程方法来去除 PDF 中的水印。Aspose.PDF 提供可靠且可定制的解决方案,可无缝集成到各种应用程序中,确保准确性并保持文档完整性。
优秀的界面控件开发包,帮助企业构建卓越应用!
DevExpress DXperience Subscription高性价比的企业级.NET用户界面套包,助力企业创建卓越应用!
DevExpress WinForms Subscription为Windows Forms平台创建具有影响力的业务解决方案,高性价比WinForms界面控件套包。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢