Listview首列固定,不能移动到其他列

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); } } }

  

posted @ 2012-11-12 16:28  xiaokang088  阅读(2815)  评论(1编辑  收藏  举报