ListView的首列是checkbox,所以想固定首列,不能移动。
本想找到根本的解决办法,没找到。所以弄了这个笨办法。哪位知道怎么根本解决,麻烦告知,谢谢。
var view = this.lvFiles.View as GridView; if (view != null && view.Columns != null) view.Columns.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Columns_CollectionChanged); } void Columns_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Move) { var view = this.lvFiles.View as GridView; if (view == null) return; if (view.Columns == null) return; if (e.NewStartingIndex == 0) { view.Columns.CollectionChanged -= new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Columns_CollectionChanged); view.Columns.Move(e.NewStartingIndex, e.OldStartingIndex); view.Columns.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Columns_CollectionChanged); } if (e.OldStartingIndex == 0) { view.Columns.CollectionChanged -= new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Columns_CollectionChanged); view.Columns.Move(e.NewStartingIndex, e.OldStartingIndex); view.Columns.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Columns_CollectionChanged); } } }