Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single-select Win32 ListView (Common Controls)

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
);
like image 221
Miquella Avatar asked Dec 13 '22 19:12

Miquella


2 Answers

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.

like image 113
Greg Domjan Avatar answered Dec 27 '22 23:12

Greg Domjan


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

like image 21
Bill Forster Avatar answered Dec 28 '22 00:12

Bill Forster