简体   繁体   English

在gridcontrol devexpress中添加新的自定义列

[英]Add new custom column in gridcontrol devexpress

I am new to Devexpress. 我是Devexpress的新手。 Now i need help from anybody to go ahead. 现在我需要任何人的帮助才能继续。 I have a gridcontrol in a windows application. 我在Windows应用程序中有一个gridcontrol。 The Data inside the gridcontrol is unbounded using EntityFramework. gridEntity内部的数据使用EntityFramework是不受限制的。 There are plenty of columns inside it. 里面有很多列。 There are two columns named AmountDroppped and TransactionAmount. 有两列名为AmountDroppped和TransactionAmount。 I need to add another columns to display the difference between these columns and i wanna make reddish the whole row if this custom column value is greater than 400INR. 我需要添加其他列以显示这些列之间的差异,并且如果此自定义列值大于400INR,我想使整个行带红色。 Is there any way to do this without using code behind and stored procedure. 有什么方法可以执行此操作而无需使用背后的代码和存储过程。 Hope there might be a one. 希望有一个。

I suggest you to use the Unbound Columns feature and it's Expressions to implement custom column that display the difference between two bound 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);

To conditionally highlight some specific rows I suggest you use the Style Format Conditions feature: 要有条件地突出显示某些特定的行,建议您使用“ 样式格式条件”功能:

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);

Related help-article: Design-Time Features > Grid Designer > Style Format Conditions Page 相关帮助文章: 设计时功能>网格设计器>样式格式条件页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM