如何防止列在ListView中移动?
问题描述:
我在列表视图中有列。我允许他们搬走。如何防止列在ListView中移动?
现在,我想要位置0的列始终保持在该位置。到目前为止,我只设置一个简单的代码,当一列移动触发:
Is column the first one?
If yes switch it back with the column it was just swapped.
不过,我想可以防止移动,使柱0不能在所有移动。有没有办法做到这一点?像“列冻结”这样的属性?
答
您可以处理ListView.ColumnReordered事件。检查新旧索引是否等于0
并取消列重新排序:
private void listView1_ColumnReordered(object sender, ColumnReorderedEventArgs e)
{
if (e.NewDisplayIndex == 0 || e.OldDisplayIndex == 0)
e.Cancel = true;
}