【问题标题】:How to refresh row of DataGrid when DataGrid is binded to DataTable?DataGrid绑定到DataTable时如何刷新DataGrid的行?
【发布时间】:2012-07-05 15:59:27
【问题描述】:

DataGrid 绑定到某个 DataTable。 用户更改了一些值。我想用一些颜色标记更改的行。 我已经做到了。但是如何通知 DataGrid,当前行的值已经改变了?

附:我在 currentRow.Row.RowState 上使用触发器来指示更改的行。我不想刷新所有 ItemsSource - 它的操作太长了。

【问题讨论】:

    标签: c# .net wpf datagrid datatable


    【解决方案1】:

    这些方面的东西可能有助于配合....它不准确,您可能必须在不同的事件句柄上调用它..但它应该为您指明正确的方向!

    private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                int colIndex = e.ColumnIndex;
                int rowIndex = e.RowIndex;
    
                DataGridViewRow theRow = dgvOutstandingReports.Rows[rowIndex];
    
    
                theRow.DefaultCellStyle.BackColor = Color.LightYellow;
            }
    

    【讨论】:

      【解决方案2】:

      不是最好的决定,但它按我的预期工作:

      dataView.ListChanged += (o, e) =>
      {
          if (e.ListChangedType == ListChangedType.ItemChanged)
          {
              DataRowView row = ((DataView)o)[e.NewIndex];
              if(row != null)
              {
                  MethodInfo method = typeof(DataRowView).GetMethod("RaisePropertyChangedEvent", BindingFlags.Instance | BindingFlags.NonPublic);
                  method.Invoke(row, new object[] { "Row" });
              }
          }
      };
      

      【讨论】:

        猜你喜欢
        • 2013-10-22
        • 2011-10-12
        • 2014-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-28
        • 1970-01-01
        相关资源
        最近更新 更多