Difference between two datagrid column values ​​and displaying the result in a new column

I have a datagrid that displays a table from a database as follows:

enter image description here

I need to add a new column called " Difference ", which should display the difference between the value of the Scores1 column and the value of the Scores2 column.

(PS: negative values ​​from the difference)

How to do it in WPF?

+4
source share
2 answers

I am not familiar with WPF, but does wpfdatagrid TemplateField or any other related structure?

If so, you can do it like this:

 <ItemTemplate> <asp:Literal ID="Literal4" runat="server" Text='<%# (Decimal.Parse(Eval("Score1")) - Decimal.Parse(Eval("Score2")) %>'> </asp:Literal> </ItemTemplate> 

NOTE This code is for Gridview . This does not work on wpfdatagrid , but it may give you an idea.

0
source

Make a request / view / saved process for it

eg. sort of

Select Scores1, Scores2, case When Scores1 - Scores2> 0, then Scores1 - score2 else 0 end as Difference From SomeTable

You can add a column to the data grid and populate it, but it is much more useless.

0
source

All Articles