Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm using WPF listView with N number of columns where the 1st column must behave like a margin column and it should remain the 1st all the times </p> <p>How Can I disable the re-order for 1st column only, and keep other columns "reorder-able"?</p> <p>I can disable the drag-drop of the 1st column using IsHitTestVisible property which will disable the mouse inputs, but I noticed that user can drag the 2nd column (for example) and drop it right before the 1st column and this will swap the 1st column with the 2nd column?</p> <p><strong>I figured out how to do it:</strong></p> <p>1) first subscribe to the event:</p> <pre><code>GridView gridView = this.dbListView.View as GridView; gridView.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler(Columns_CollectionChanged); </code></pre> <p>2) Event handler is:</p> <pre><code> /// &lt;summary&gt; /// 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 /// &lt;/summary&gt; /// &lt;param name="sender"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; 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); }); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload