Discussion:
Listview - keep a selection when clicking a subitem ?
(too old to reply)
R.Wieser
2022-10-01 10:45:03 UTC
Permalink
Hello all,

I've created a listview with a few columns which allows multiple rows to be
selected.

The thing is that I would like to be able to select a few rows and than
click subitems without loosing that selection.

I've been looking if I could ignore the LVN_SELECTIONCHANGED notification,
but that one doesn't even return a value. And as the NM_CLICK notification
comes in after all the changes its not usable either.

tl;dr:
Does anyone know how to keep a set of rows selected when clicking a subitem
?

Or maybe the other way around : can I limit the selection of rows to only
when clicking the main item row ?

Regards,
Rudy Wieser
JJ
2022-10-01 14:16:48 UTC
Permalink
Post by R.Wieser
Hello all,
I've created a listview with a few columns which allows multiple rows to be
selected.
The thing is that I would like to be able to select a few rows and than
click subitems without loosing that selection.
I've been looking if I could ignore the LVN_SELECTIONCHANGED notification,
but that one doesn't even return a value. And as the NM_CLICK notification
comes in after all the changes its not usable either.
Does anyone know how to keep a set of rows selected when clicking a subitem
?
Or maybe the other way around : can I limit the selection of rows to only
when clicking the main item row ?
Regards,
Rudy Wieser
Hold CTRL key for selecting more items without deselecting existing item(s).
R.Wieser
2022-10-01 18:38:45 UTC
Permalink
JJ,
Post by JJ
Hold CTRL key for selecting more items without deselecting existing item(s).
I know, thats not the problem. I have the need to be able to click
subitems (no ctrl or shift held) *without* the selection mechanism kicking
in.

And by the way: Have you ever tried to ctrl-click items and than click a
subitem ? The selection for that row will toggle ...

Hmm.... I just checked, for a reference, what OE6 does in such a case
(trying to set the 'ignore' state for a set of rows). The other selected
rows and the last (ctrl-selected) one do not change status at the same
moment - due to that last row getting its selection toggeled when again
ctrl-clicked.

.... and that might mean that I set my goal a bit to high ....

Regards,
Rudy Wieser
R.Wieser
2022-10-02 08:41:37 UTC
Permalink
JJ,
Post by JJ
Hold CTRL key for selecting more items without deselecting existing item(s).
I forgot to explicitily mention that I'm using the listview in LVS_REPORT
style.

Something "funny" :

Using a basic listview (no LVS_EX_FULLROWSELECT) you *cannot* select rows
other than by clicking on the main items column, but clicking /anywhere/ on
a row *will* drop the (carefull) selection you made. Go figure ...

There might be a reason for doing it that way, but I'm not yet been able to
figure it out.

Regards,
Rudy Wieser
JJ
2022-10-02 12:31:27 UTC
Permalink
Post by R.Wieser
I forgot to explicitily mention that I'm using the listview in LVS_REPORT
style.
Using a basic listview (no LVS_EX_FULLROWSELECT) you *cannot* select rows
other than by clicking on the main items column, but clicking /anywhere/ on
a row *will* drop the (carefull) selection you made. Go figure ...
There might be a reason for doing it that way, but I'm not yet been able to
figure it out.
Regards,
Rudy Wieser
Might want to try injecting CTRL key event at the correct time. e.g. when
mouse enters the ListView and when there's existing selection.
R.Wieser
2022-10-02 15:48:15 UTC
Permalink
JJ,
Post by JJ
Might want to try injecting CTRL key event at the correct time.
e.g. when mouse enters the ListView and when there's existing
selection.
I'm afraid that the/my problem already shows itself when doing the first
selection and than clicking a subitem column (to effect a change al-la OE6
with its "ignore" (spectacle icon) column). I'm confident it will do the
same on a second selection (without my mouse having left the listview
controls window).

Another "funny" one : Select a few rows (using shift-click) and than do a
ctrl-click afterwards (selecting a new or deselecting a currently selected
row). After that there is no way to click anywhere (on a subitem or
otherwise) to effect a change without either loosing the selection
(shift-click) or unselecting the row you click (ctrl-click) and having to
click it again to select it again. Fun when you want to toggle something
in all of those rows ...

I already tried to fight the selection mechanism by capturing
LVN_ITEMCHANGING and in certain cases disallowing a change*, but than
strange stuff started to happen when I continued ctrl-clicking rows.

* a problem in itself, 'cause multiple changes (selected, focussed) can
occur at the same time, and it seems to be an all-or-nothing rejection.

Currently I've chosen to ignore, in the listviews NM_CLICK notification
code, the ctrl/shift click on a subitem if its done on an (just switched to)
unselected row. It makes sure that if a change is made its made on all rows
at the same time.

... I might include a check to see if the clicked row is the only one
selected, and than effect a non-ctrl/shift click too.

I must say, I really enjoy working with those basic, freely configurable
controls. /s

Regards,
Rudy Wieser
Paul N
2022-10-18 13:31:30 UTC
Permalink
Post by R.Wieser
Hello all,
I've created a listview with a few columns which allows multiple rows to be
selected.
The thing is that I would like to be able to select a few rows and than
click subitems without loosing that selection.
I've been looking if I could ignore the LVN_SELECTIONCHANGED notification,
but that one doesn't even return a value. And as the NM_CLICK notification
comes in after all the changes its not usable either.
Does anyone know how to keep a set of rows selected when clicking a subitem
?
Or maybe the other way around : can I limit the selection of rows to only
when clicking the main item row ?
Just a suggestion, and I'm a bit late to the party, but... I'm guessing that the unwanted effects happen when the control receives a WM_LBUTTONDOWN message. Would it be possible to subclass the control and intercept that message? You could see what is being clicked on (don't know how easy that would be) and what the current state of the control is, and if the normal result is not what you want then change the message to a different one and/or do something directly.
R.Wieser
2022-10-19 08:52:44 UTC
Permalink
Paul,
Post by Paul N
Would it be possible to subclass the control and intercept that message?
At some point I was considering the same. Up until the point I realized I
would be fighting the build-in selection method, and could only hope it
would not get out on sync or have wierd side effects (i've tried some other
build-in(!) stuff which did just that).

Next to that I still needed the click event so I could do my own thing.
That means I would either had to move code from outside the listview to
inside it, of fake my own notification.

In the end I decided that especially the fighting was not worth it, and
setteled on not executing my own code when a subitem was clicked and (as a
result) was just deselected.

Thanks for the suggestion though.

Regards,
Rudy Wieser

Loading...