当DataGrid绑定到DataTable时,如何刷新DataGrid的行?

时间:2012-07-05 09:04:08

标签: c# .net wpf datagrid datatable

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

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

2 个答案:

答案 0 :(得分: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;
        }

答案 1 :(得分: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" });
        }
    }
};
相关问题