1 つのフォームで DataGrid を使用する WPF アプリケーションがあります。実行時に DataTemplate 列に値を入力すると、その特定の列の SUM を DATAGRID フッターに表示する必要があります。そのため、その AMOUNT 列のセルの値を変更するたびに、その列の正しい SUM を表示する必要があります。どのイベントに挑戦するべきか。このコードを試してみましたが、毎回タブを押す必要があり、正しい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();
}
}