2009-07-24 14 views

答えて

23
<ListView.View> 
    <GridView AllowsColumnReorder="False"> 
     ......headers here........ 
    </GridView> 
</ListView.View> 

私は第一列はマージン欄のように動作しなければならない、それは常にどのよう

第一残るべき列のN番号とWPFのListViewを使用しています。この

4

をお試しください1列目のみの再注文を無効にし、他の列を「並べ替え可能」にすることはできますか?

マウス入力を無効にするIsHitTestVisibleプロパティを使用して第1列のドラッグドロップを無効にすることはできますが、ユーザーは第2列(たとえば)をドラッグして第1列の直前にドロップすることができます。第1列と第2列を入れ替えますか?

私はそれを行う方法を考え出し:

1)最初のイベントをサブスクライブ:

GridView gridView = this.dbListView.View as GridView; 
gridView.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler(Columns_CollectionChanged); 

2)イベントハンドラは、次のとおりです。

/// <summary> 
    /// This event is executed when the header of the list view is changed - 
    /// we need to keep the first element in it's position all the time, so whenever user drags any columns and drops 
    /// it right before the 1st column, we return it to it's original location 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    void Columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
    { 
     GridViewColumnCollection collection = (GridViewColumnCollection)sender; 
     if (e.Action == NotifyCollectionChangedAction.Move) //re-order event 
     { 
      if (e.NewStartingIndex == 0) //if any of the columns were dragged rigth before the 1st column 
      { 
       this.Dispatcher.BeginInvoke((Action)delegate 
       { 
        GridView gridView = this.dbListView.View as GridView; 
        //removing the event to ensure the handler will not be called in an infinite loop 
        gridView.Columns.CollectionChanged -= new NotifyCollectionChangedEventHandler(Columns_CollectionChanged); 
        //reverse the re-order move (i.e. rolling back this even) 
        collection.Move(e.NewStartingIndex, e.OldStartingIndex); 
        //re-setup the event to ensure the handler will be called second time 
        gridView.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler(Columns_CollectionChanged); 
       }); 
      } 
     } 

    } 
関連する問題