在gridcontroldevexpress中添加新的自定义列
本文关键字:自定义 添加 gridcontroldevexpress | 更新日期: 2023-09-27 18:17:20
我是Devexpress的新手。现在我需要任何人的帮助才能继续前进。我在windows应用程序中有一个网格控件。gridcontrol中的数据使用EntityFramework是无界的。里面有很多柱子。有两个列,分别是amountdropped和TransactionAmount。我需要添加另一列来显示这些列之间的差异,如果这个自定义列值大于400INR,我想使整行变红。有没有办法在不使用后台代码和存储过程的情况下做到这一点?
我建议您使用Unbound Columns功能和它的表达式来实现自定义列,显示两个绑定列之间的差异:
using DevExpress.XtraGrid.Columns;
//...
GridColumn columnDiff = new GridColumn();
columnDiff.FieldName = "amountDiff";
columnDiff.Caption = "Diff";
columnDiff.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
columnDiff.UnboundExpression = "[TransactionAmount] - [AmountDroppped]";
gridView1.Columns.Add(columnDiff);
要有条件地突出显示某些特定行,我建议您使用样式格式条件功能:
using DevExpress.XtraGrid;
StyleFormatCondition condition = new DevExpress.XtraGrid.StyleFormatCondition();
condition.Appearance.BackColor = Color.Red;
condition.Appearance.Options.UseBackColor = true;
condition.ApplyToRow = true;
condition.Condition = FormatConditionEnum.Expression;
condition.Expression = "([TransactionAmount] - [AmountDroppped]) > 400";
gridView1.FormatConditions.Add(condition);
相关帮助文章:Design-Time Features> Grid Designer> Style Format Conditions Page