Discussion:
CListCtrl::SetItemState() and keyboard navigation
(too old to reply)
p***@gmail.com
2008-03-16 04:41:43 UTC
Permalink
I'm attempting to progmatically select a single row in a CListCtrl
using the following:

m_list.SetItemState(-1, 0, LVIS_SELECTED); // deselect all rows
m_list.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); // select row i

However, after doing this, the arrow keys don't select the row
adjacent to i (instead they select the row adjacent to the row
previously selected by a mouse click or via keyboard navigation).

To illustrate the problem, let i=10. If I navigate to row 5 using the
keyboard and then call the method containing the above code then row
10 is selected. If I then press the down arrow key, row 6, instead of
row 11, is selected.

Could someone please advise how to resolve this ?

Regards,

Patrick
David Lowndes
2008-03-16 09:49:02 UTC
Permalink
Post by p***@gmail.com
I'm attempting to progmatically select a single row in a CListCtrl
m_list.SetItemState(-1, 0, LVIS_SELECTED); // deselect all rows
m_list.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); // select row i
However, after doing this, the arrow keys don't select the row
adjacent to i (instead they select the row adjacent to the row
previously selected by a mouse click or via keyboard navigation).
Patrick,

Try setting LVIS_FOCUSED as well as LVIS_SELECTED.

Dave
s***@gmail.com
2016-10-13 13:27:25 UTC
Permalink
Post by p***@gmail.com
m_list.SetItemState(-1, 0, LVIS_SELECTED); // deselect all rows
Is that -1 parameter an undocumented feature?

Thanks in advance.

Loading...