Search code examples
c++winapilistviewwtl

List view control loses performance with large number of columns


I have a virtual listview control in report mode whose items I draw manually by handling NM_CUSTOMDRAW notification. The problem I have is that my performance drops proportionaly to the number of columns. By debugging the code I noticed that my OnCustomDraw and OnGetDispInfo is called for items that are not even visible in the client window.

If I have a list view with 1.000 rows and 100 columns of which only 10 rows and 5 columns are visible I noticed that OnCustomDraw and OnGetDispInfo will be called for each element in this 10 rows. Listview will send me notifications for all the 95 columns that are not visible.

Has anybody encountered a problem like this?


Solution

  • The ListView is implemented just the way it is. Just the following optimization has come to my mind:

    Via control subclassing, track a list of visible columns. In the list view subclass proc, you probably need to handle the following messages (and maybe more if I forgot something):

    • WM_CREATE
    • WM_SIZE
    • WM_HSCROLL
    • WM_NOTIFY (if ((NMHDR*)lParam)->hwndFrom is from the embedded header control; see docs for LVM_GETHEADER)

    Whenever any of these messages comes, let the original proc to handle it, and then update the list of currently visible columns (see HDM_GETITEMRECT).

    When handling NM_CUSTOMDRAW in the dialog/window procedure consult the list of visible columns and paint only if visible.