Menu

Q: CListView OnLVNDispInfo and Sorting, or: where best to fetch the data

Help
peterme
2014-12-10
2014-12-11
  • peterme

    peterme - 2014-12-10

    Hello,

    I tried to implement column sorting on column header click within the Explorer sample
    and basically it works nearly fine. - For that, i did need to:

    • eextend the CompareProc function, using lParamSort for to detect column and sort directrion;
    • extend the nested class ListItemData by some few extra fields, ie. for to store the file size information
    • to store zhis information within CMyListView::OnLVNDispInfo, because herein it is already available
      by file access and i didn't want to access files unnecessarily twice.
      -
      All works fine, except: before sorting all listview lines must be visible, because otherwise the initializing of date in OnLVNDispInfo will not happen. If lines are not visible, the data are not intialized and the sort fails.
      -
      Obviously the virtual listview paradigm conflicts the needs for sorting: that all data need to be initialized before sorting.
      -
      The problem does not occur related to the inital SortItems(CompareProc, 0), as done within DoDisplay().
      This is because: the item data used by the CompareProc are PIDLs that had been stored earlier,
      namely in EnumObjects, where the ListItemData objects are created, and later on available for CompareProc anyway.

    So, regarding that: my problem of understanding is, what is the approach recommended by concept:
    a) to force somehow all Listview lines to become visible before sorting (bad brute force: scroll ....)
    b) or to move the storing of data - and that means all file access operations - at all from OnLVNDispInfo to EnumObjects.
    Approach b) would allow Sorting, but obviouly is againt the spirit of the virtual parading (fetching uselesss data for lines that are not visible).
    -
    Any hints for the recommended strategy would be very helpful.

    P.

     
  • David

    David - 2014-12-11

    Hi P.

    This guess might be wide of the mark, but if we are simply looking at a display timing issue (seeing the columns momentarily before they are sorted) then SetRedraw might prove useful. We can use SetRedraw(FALSE) to suspend the drawing of a window while changes are made, and then use SetRedraw(TRUE) followed by RedrawWindow when the window is ready to be displayed. This trick is used in CMainFrame::OnDefaultLayout() in the DockTabbedMDI sample.

    Best regards,
    David

     
  • peterme

    peterme - 2014-12-11

    Hi David,

    unfortunately not quite ... all those SetRedraw, Invalidate, RedrawWindow, UpdateWindow (and others i did try) techniques obviously refer to the refresh of the visible area or region but don't lead to trigger the LVN_GETDISPINFO. The latter one is called by Windows if we eg. move the horiz. scrollbar, in which case the sorting would work correctly, because all needed getdispinfo calls for providing the line's information would have been done at that point.
    After a lot of testing i was not able so far to provoke the LVN_GETDISPINFO programatically, even not by line loops on EnsureVisible etc.
    Trace shows that the getdispinfo is called for the visible lines plus one.
    So what i fear is that i need to provide the listitem data earlier, not in getdispinfo but within the EnumObjects, what is against the spirit of the virtual listview in my eyes.
    Not an issue at all for this fine wrapper Win32++ of course! Only i problem i just have with window's virt. listview and sortitems when tring the explorer sample a bit.

    Many thanks for your attention and best Regards!
    P.

     

Log in to post a comment.

Auth0 Logo