[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Setting Current Row in a CListCtrl

Posted on 2009-05-11
7
Medium Priority
?
1,414 Views
Last Modified: 2013-11-20
I have a CListCtrl that uses a virtual list with user drawn data allowing for mulitple selections.
When the user clicks on a header, the logic changes the sort order and re-sorts the data.
What is working great is the logic that first records which items are currently selected, resorts the list, and reselects the selected items even though they have moved positions.
But what else is happening to me is the "current" item does not change.

As an example, say I have a List where Item #2 is selected.  If I hit the down arrow, the list changes the selected item to #3.  If I click a header and resort the data, what was item #3 is not item #7, and item #7 is selected (by virtue of the item highlighted in blue).  But item #3 still has a dash rectangle around it, and if I hit the down arrow, item #4 becomes selected rather than #8.

I am NOT using Hot cursors.  Based on the documentation, I would have thought CListCtrl::SetSelectionMark would allow me to update which item that dash rectangle would apper.  But when I tried hard coding the selection mark to say item #2, the dash rectangle didn't move.

So what do I need to call to move that dash rectangle?  
0
Comment
Question by:HooKooDooKu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 24361526
Actually it is behaving correctly, just because the contents of the selected row have been changed doesn't mean it 'searches' for where the previous information was.

Deselect the row selected, sort, select the row you now want selected.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 total points
ID: 24362686
>>>> Actually it is behaving correctly
Don't think so. The hi-lited and selected row also should be the focused one.

You might consider on handling the LVN_ITEMCHANGED notification message in your dialog or view class. Then for any change of selection you could update the state of the selected item so that it is focused as well.

void CTestDlgDlg::OnLvnItemchangedList1(NMHDR *pNMHDR, LRESULT *pResult)
{
   LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
   if (myList1.GetItemState(pNMLV->iItem, LVIS_FOCUSED) == 0) 
   {
       myList1.SetItemState(pNMLV->iItem, LVIS_FOCUSED,
                                          LVIS_FOCUSED);
   }
 
    *pResult = 0;
}

Open in new window

0
 
LVL 16

Author Closing Comment

by:HooKooDooKu
ID: 31580396
BINGO!
Didn't have to handle any notification messages.  Just had to update the code where I was already using SetItemState() with LVIS_SELECTED to also specify LVIS_FOCUSED for the 1st item that gets selected.

Thanks.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24365197
>>>> Just had to update the code where I was already using SetItemState() with LVIS_SELECTED

Good. Assume you now have

myList1.SetItemState(item, LVIS_FOCUSED | LVIS_SELECTED
                                   LVIS_FOCUSED | LVIS_SELECTED);

Or you may add the LVIS_DROPHILITED both for settings and mask argument.

But you have to be cautious when actively calling SetItemState() so to not get a deadlock when handling any notifications. Unfortunately the SetItemxxx calls
cannot be made to not invoking new notifications. As long as you didn't handle the notifications you are safe.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 24365326
>>>> Just had to update the code where I was already using SetItemState() with LVIS_SELECTED



I assume that came from a comment to the expert given the points.
precisely - what I told you to do.
0
 
LVL 16

Author Comment

by:HooKooDooKu
ID: 24365940
@ itsmeandnobodyelse
Fortunately I am either not responding to the generated notifications, or for the ones I am responding to, the response is to update another window with additional data that matches the FOCUSED item.  So it's working great, but thanks for the warning.

@AndyAinscow
My problem was NOT with what items were selected.  I had long ago learned how to use SetItemState() and LVIS_SELECTED to select and unselect items.

My problem was that I only recently learned I had a problem with the FOCUS rectangle.  My problem was that I didn't know how to update the FOCUS rectangle (I just couldn't think to call it that) and didn't even think to relook at SetItemState().

itsmeandnobodyelse was given the points for typing two word: "SetItemState" and "LVIS_FOCUSED".  That was what I was missing.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 24366043
Aha, now I get it.  Thanks for clarifying.  (When I select an item I set the focus at the same time  LVIS_FOCUSED | LVIS_SELECTED, It didn't occur to me that you wouldn't realise that was required. )
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question