C#WinForm DataGridView过滤器暂停

时间:2012-08-31 07:21:23

标签: c# datagridview filter dataset


我有一个VisualStudio生成的数据集 我将它们连接到DataGridView(由VisualStudio连接的宽度) 我正在使用过滤器。例如:
xyBindingSource.Filter = "yx = 'tart'";

我的问题:
如果我更改了yx列的任何值(从tart到其他任何值),更改的行将在CellEndEdit事件运行之前删除。
在CellEndEdit事件中,DataGridViewCellEventArgs将包含正确的行号和列号。
但事件args指向的行不是那个,编辑的是什么,因为之前删除了所选的行
我该怎么办?

谢谢你的帮助:
Norbi

1 个答案:

答案 0 :(得分:0)

您可以使用DataGridView.CurrentCellDirtyStateChanged事件处理此问题。这可以引发DataGridView.CellValueChanged事件,如果你这样做:

void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

CommitEdit手动提升DataGridView.CellValueChanged事件。您可以再次在此活动中重新加载Filter方法。试一试。