views:

24

answers:

3

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
);
A: 

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

Bill Forster
+1  A: 

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
Thank you for the extra information on not being able to toggle it, that will actually come in very handy!
Miquella
+1  A: 

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

Nate
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