我们有 WPF 应用程序,其中我们在一个表单上使用 DataGrid。在运行时,当我们在 DataTemplate 列中输入值时,我需要在 DATAGRID 页脚中显示该特定列的 SUM。因此,当我每次更改该 AMOUNT 列的任何单元格中的值时,都需要显示该列的正确 SUM。我应该尝试哪个事件。我试过这段代码,但每次都需要按tab,它不显示正确的SUM。
private void dgInfo_RowEditEnding(object sender, Microsoft.Windows.Controls.DataGridRowEditEndingEventArgs e)
{
Microsoft.Windows.Controls.DataGridRow row = this.dgInfo.ItemContainerGenerator.ContainerFromIndex(e.Row.GetIndex()) as Microsoft.Windows.Controls.DataGridRow;
ContentPresenter CP = dgInfo.Columns[3].GetCellContent(row) as ContentPresenter;
TextBlock t = FindVisualChild<TextBlock>(CP);
if (t != null && t.Text.Length > 0)
{
decimal d = Convert.ToDecimal(t.Text);
sum = sum + d;
txtTotal.Text = sum.ToString();
}
}