Search code examples
wpfwpf-controlswpfdatagridwpftoolkit

Calculate SUM of "Amount" column in DATAGRID's DataGridTemplateColumn on in WPF


We have WPF application, In which we use DataGrid on one form. Now we want to calculate total of "AMOUNT" column of that datagrid on Winddow_Loaded event, So can it will display total of AMOUNT column in one TextBox when Form get loaded. So how to iterate through all rows in DATAGRID & Calculate Total of "AMOUNT" column.

How to show this total in Footer of WPF Datagrid.?


Solution

  • Bind DataGrid to DataTable. After that you can just iterate through all rows:

            double sum = 0;
            foreach (var row in myTable)
            {
                sum += double.Parse(row["AMOUNT"].ToString());
            }
            myTextBox.Text = sum.ToString()