4

I'm using the ListView control from Common Controls 6.0 in C++ and I need the ListView to be single-select only.

All of the higher level controls have this feature (e.g. .Net and Qt), but I imagine they are based on this control deep down somewhere. Any ideas on how I can get this to behave as a single-select list?


Just in case it makes a difference, here is my current create statement:

list = ::CreateWindowExW(
    0,
    WC_LISTVIEWW,
    NULL,
    WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_SHOWSELALWAYS | LVS_REPORT | LVS_OWNERDATA,
    0,
    0,
    250,
    400,
    parentWindow,
    NULL,
    NULL,
    NULL
);
Miquella
  • 1,074
  • 2
  • 13
  • 25

4 Answers4

7

You want the flag LVS_SINGLESEL

This flag must be used in window creation, changing it after creation will fail - can't toggle between single and multi select without creating 2 separate controls.

Greg Domjan
  • 13,943
  • 6
  • 43
  • 59
  • 1
    Thank you for the extra information on not being able to toggle it, that will actually come in very handy! – Miquella Oct 11 '10 at 22:07
3

There's a LVS_SINGLESEL style. Just OR that in with the styles you already have.

Bill Forster
  • 6,137
  • 3
  • 27
  • 27
2

You want LVS_SINGLESEL. See: http://msdn.microsoft.com/en-us/library/bb774739.aspx

Nate
  • 18,752
  • 8
  • 48
  • 54
  • Thanks for the link to the documentation, I swear I looked through that list five different times... Maybe it was the extended styles I was looking through, actually... – Miquella Oct 11 '10 at 22:11
1

If you don't want add any code, just edit the Dialog RC property. enter image description here

Zhang
  • 3,030
  • 2
  • 14
  • 31