Hi,
I have a DataGrid on a WPF window.
The window code contains a method that calculates the total value of a column.
The only problem is if the DataGrid has rows but one or more of the cells in that column have no value, the application throws an error.
Here is the method that I am using:
private string CalculateTotalPrice() { decimal finalTotalPrice = 0; try { finalTotalPrice = dgvTransactionData.ItemsSource.Cast<DataRowView>() .Sum(rowView => (decimal)rowView["Total Item Price"]); } catch (Exception exception) { Dal.ErrorMessage(exception); } return finalTotalPrice.ToString("C"); }
The error message is:
An unhandled exception of type 'System.InvalidCastException' occurred in CheckoutPOS.exe
Additional information: Specified cast is not valid.
and it occurs on the LINQ statement in the try block.
Any thoughts???
Thanks for the help in advance! :)
From, Nathaniel Peiffer