Search code examples
c#wpfwpfdatagrid

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


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

enter image description here

I have to added a new column called "Difference" which should display the difference between the Scores1 column value & the Scores2 column value.

(P.S : No negative values from the difference)

How to achieve this in WPF?


Solution

  • I'm not familiar with WPF but, Is wpfdatagrid has TemplateField or any other related structure ?

    If so, you can done 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 for Gridview. It doesn't work on wpfdatagrid but it can gives you an idea.