I have two ListViews in my app, with an initially identical collection of columns. When the user reorders the columns in one, I want the columns in the other to be reordered.
I have the following event handler on one of the views' ColumnReordered event, and the corresponding handler on the other:
private volatile bool reorderingColumns;
private void listView1_ColumnReordered(object sender, ColumnReorderedEventArgs e)
{
// Prevent reentry - is this necessary?
if (reorderingColumns)
return;
try
{
reorderingColumns = true;
// copy display indices to the other listView
for (int i = 0; i < columnInfo.Count; i++)
{
listView2.Columns[i].DisplayIndex = listView1.Columns[i].DisplayIndex;
}
}
finally
{
reorderingColumns = false;
}
}
however, the order of the columns in the second listview remains unchanged. What do I need to do to get the second listview to redraw its columns in the new order?