简体   繁体   中英

Add new custom column in gridcontrol devexpress

I am new to Devexpress. Now i need help from anybody to go ahead. I have a gridcontrol in a windows application. The Data inside the gridcontrol is unbounded using EntityFramework. There are plenty of columns inside it. There are two columns named AmountDroppped and 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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