【问题标题】:How to prevent column to be moved in a ListView?如何防止列在 ListView 中移动?
【发布时间】:2017-02-16 22:48:29
【问题描述】:

我在 ListView 中有列。我允许他们移动。

现在,我希望位置 0 的列始终保持在该位置。到目前为止,我只设置了一个在移动列时触发的简单代码:

Is column the first one?
If yes switch it back with the column it was just swapped.

但是,我希望阻止移动,以便根本无法移动第 0 列。有没有办法做到这一点?像“列冻结”这样的属性?

【问题讨论】:

    标签: c# winforms listview


    【解决方案1】:

    您可以处理ListView.ColumnReordered 事件。检查新旧索引是否等于0并取消列重新排序:

    private void listView1_ColumnReordered(object sender, ColumnReorderedEventArgs e)
    {
        if (e.NewDisplayIndex == 0 || e.OldDisplayIndex == 0)
            e.Cancel = true;
    }
    

    【讨论】:

      猜你喜欢
      • 2010-09-17
      • 2023-03-13
      • 2020-04-09
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多