【问题标题】:C# WinForm DataGridView Filter pauseC# WinForm DataGridView 过滤器暂停
【发布时间】:2012-08-31 07:21:23
【问题描述】:


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

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

我该怎么办?

感谢您的帮助:
诺比

【问题讨论】:

    标签: c# datagridview filter dataset


    【解决方案1】:

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

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

    CommitEdit 手动引发 DataGridView.CellValueChanged 事件。您可以再次在此事件中重新加载您的 Filter 方法。试试看吧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多