TalkingCode
TalkingCode

Reputation: 13567

WPF Listview : Column reorder event?

I need to sync the column order of two ListViews event when the user changes the order. But it seems there is not a Column reorder event.

For the moment I just did a AllowsColumnReorder="False" but that is not a permanent solution. While searching the net I found many people with the same problem but no solution. What can be done?

Upvotes: 3

Views: 5656

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292735

I'm not sure it works, but you could probably take advantage of the fact that GridView.Columns is an ObservableCollection : you could subscribe to the CollectionChanged event and handle the case where Action = Move

GridView gridView = (GridView)listView.View;
gridView.Columns.CollectionChanged += gridView_CollectionChanged;

private void gridView_CollectionChanged(object sender, CollectionChangedEventArgs e)
{
    if (e.Action == NotifyCollectionChangedAction.Move)
    {
        string msg = string.Format("Column moved from position {0} to position {1}", e.OldIndex, e.NewIndex);
        MessageBox.Show(msg);
    }
}

Upvotes: 12

Related Questions