dimanche 28 juin 2015

C# WPF Sum datagrid column to label

I am having problems adding up all of the values in a WPF Datagrid column to a label upon a change event (probably SelectionChanged). I have this code:

private void tblData_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
        decimal total = 0;

        foreach(DataRowView rowView in (DataView)this.tblData.ItemsSource)
        {
            total += (decimal)rowView["Total"];
        }
        lblTotal.Content = total.ToString();
}

But it breaks my program, it throws a 'System.InvalidCastException'. Can anyone please look at my code and help me figure out what I am doing wrong?

Aucun commentaire:

Enregistrer un commentaire