2

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

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

4

2 回答 2

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;
        }
于 2012-07-09T08:52:35.243 回答
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" });
        }
    }
};
于 2012-07-12T12:17:10.963 回答