0

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();
      }
 }
4

1 に答える 1

0
 void dgInfo_CellEditEnding(object sender, Microsoft.Windows.Controls.DataGridCellEditEndingEventArgs e)
        {
                       decimal tot = 0;
                       GetFaltyExpenseGridResult newRecord;
                       for (int i = 0; i < (dgInfo.Items.Count - 1); i++)
                       {
                           newRecord = (GetFaltyExpenseGridResult)((ContentPresenter)dgInfo.Columns[0].GetCellContent(dgInfo.Items[i])).Content;

                           if (newRecord != null)
                           {

                                   decimal d = Convert.ToDecimal(newRecord.Amount);
                                   tot = tot + d;
                                   txtTotal.Text = tot.ToString();

                           }
                       }
       }
于 2013-02-13T08:59:13.640 に答える