【发布时间】:2012-07-05 15:59:27
【问题描述】:
DataGrid 绑定到某个 DataTable。 用户更改了一些值。我想用一些颜色标记更改的行。 我已经做到了。但是如何通知 DataGrid,当前行的值已经改变了?
附:我在 currentRow.Row.RowState 上使用触发器来指示更改的行。我不想刷新所有 ItemsSource - 它的操作太长了。
【问题讨论】:
标签: c# .net wpf datagrid datatable
DataGrid 绑定到某个 DataTable。 用户更改了一些值。我想用一些颜色标记更改的行。 我已经做到了。但是如何通知 DataGrid,当前行的值已经改变了?
附:我在 currentRow.Row.RowState 上使用触发器来指示更改的行。我不想刷新所有 ItemsSource - 它的操作太长了。
【问题讨论】:
标签: c# .net wpf datagrid datatable
这些方面的东西可能有助于配合....它不准确,您可能必须在不同的事件句柄上调用它..但它应该为您指明正确的方向!
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;
}
【讨论】:
不是最好的决定,但它按我的预期工作:
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" });
}
}
};
【讨论】: