views:

510

answers:

1

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?

+3  A: 

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);
    }
}
Thomas Levesque
Works fine so far. The syntax changed a bit. Use NotifyCollectionChangedEventArgs, e.OldStartingIndex and e.NewStartingIndex
Holli