A few ListView questions


The documentation of the ListView control (using WinApi) seem to lack some basic information, here are some questions I couldn't seem to find a solutin to:

  1. On most apps, when you double-click the border to the right of a column, the column resizes to some default width. I would have guessed that this width is specified by LVCOLUMN.cxDefault or cxIdeal, but it doesn't seem to do it. What am I missing?

  2. When you click a certain column to sort the list according to, a little arrow indicating the direction of the sort appears on top of it. How do I make it appear? BTW, does anybody know which sorting algorithm ListView uses?

  3. When in report view, any way to select a whole row instead of just the first item? (It's just a visual thing, functionally it's identical)

  4. Any way to insert multiple items at once?

Best Solution

  1. It's calculated based on the rendered width of each item in that column.
  2. The arrow is a custom image set by your program. If you don't set an image (by associating an image list with the header and then specifying an image for each header item by index), then you don't get one. I don't know what the sort algorithm is, but the item comparison algorithm is whatever you want it to be - you must specify a callback.
  3. Yes - set the LVS_EX_FULLROWSELECT extended style on the control
  4. No. But you can turn off redraw while adding multiple items.

My best recommendation for you if you're new to working with the ListView control is to read the numerous articles on CodeProject. Even if you're not working with MFC (as many of the articles are) the concepts still apply - just translate calls to the equivalent PlatformSDK macros.

Related Question