#16 Fix for column reordering in details mode

v2.0
open
nobody
None
1
2013-03-21
2013-03-21
Edwin Chen
No

My users have an issue where they reorder the columns through the columns configuration dialog but at times the columns would refuse to go to the desired position. For example, column A would not go after column B. If they are lucky they can tell column B to go before column A but it doesn't always work.

After much debugging, it appears to be a side behavior in .NET that objectlistview was not made to work with. In Utilities/ColumnSelectionForm.cs:

        // Detail view and Tile view have to be handled in different ways.
        if (view == View.Details) {
            // Of the still visible columns, change DisplayIndex to reflect their position in the rearranged list
            olv.ChangeToFilteredColumns(view);
            foreach (ColumnHeader col in olv.Columns) {
                col.DisplayIndex = visibleColumns.IndexOf((OLVColumn)col);
            }
        } else {

...

The root issue is that the order of olv.Columns is not consistent in the loop. When DisplayIndex is updated, any column that has that same DisplayIndex value is AUTOMATICALLY moved to the next available index. This helps the control avoid the situation of two columns having the same index but that causes the foreach loop to get messed up since now some columns might get skipped or columns already processed could have their DisplayIndex values shifted. A fix i just implemented and tested:

        // Detail view and Tile view have to be handled in different ways.
        if (view == View.Details) {
            // Of the still visible columns, change DisplayIndex to reflect their position in the rearranged list
            olv.ChangeToFilteredColumns(view);
            foreach (ColumnHeader col in visibleColumns) {
                col.DisplayIndex = visibleColumns.IndexOf((OLVColumn)col);
            }
        } else {

Since the loop is done on an outside list, olv.Columns items are free to move around. The first column is set, then the second, etc. so even if there is a DisplayIndex bump they are inconsequential. At the end of the foreach loop, all olv.Columns will have their appropriate DisplayIndexes set in the order they appear in visibleColumns.

If this is still not clear, feel free to ask. I use the objectlistview in virtual mode.

Edwin

Discussion