2012-07-05 47 views
2

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

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

回答

0

不是最好的决定,但它的工作原理如我所料:

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" }); 
     } 
    } 
}; 
0

沿着这些线可能会帮助队友....它不是确切的,你可能需要在不同的事件句柄上调用它,但它应该给你一个正确的方向!

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; 
     } 
+0

它不是为WPF好主意。我不想做kludje。 – Rover 2012-07-09 12:01:26