Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Toggling highlighting through a CListCtrl in the correct order

Toggling highlighting through a CListCtrl in the correct order

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sternocera
    wrote on last edited by
    #1

    Hi guys. My MFC application uses a CListCtrl with the icon style. The List Ctrl handles messages that make it select/highlight the first, previous, next and last icon, for navigation purposes. However, the order that selection toggles is wrong (it's consistent though) - It is as if the CListCtrl has a different conception of their actual order. I can toggle through the icons 1st, 4th, 2nd, 3rd. I can press "First", send a message, and get to the 1st. I can press last, and get to the third. I can toggle back and forth in that consistent, incorrect order. What might I be doing wrong? Any suggestions as to how I might solve this problem are greatly appreciated. Here is the relevant code:

    void CMyView::OnInitialUpdate()
    {
    .....
    MyListCtrl.ModifyStyle(0, LVS_AUTOARRANGE);
    MyListCtrl.SetImageList(&imgl, 0);
    LVITEM lvi0;
    lvi0.mask = LVIF_IMAGE | LVIF_TEXT;
    lvi0.iSubItem = 0;
    lvi0.pszText = "First Icon";
    lvi0.iImage = 0;

    int first\_icon = MyListCtrl.InsertItem(&lvi0);
    MyListCtrl.SetItemData(first\_icon, 1);
    ....
    

    }
    LRESULT CMyView::OnPressedFirst(WPARAM, LPARAM lParam)
    {
    ClearSelection();
    MyListCtrl.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
    return 0;
    }
    LRESULT CMyView::OnPressedPrevious(WPARAM, LPARAM lParam)
    {

    MyListCtrl.SetFocus();
    int i = MyListCtrl.GetItemCount();
    int j = 0;
    for(; j != i; ++j)
    {
    	UINT uState = MyListCtrl.GetItemState(j, LVIS\_SELECTED | LVIS\_FOCUSED);
    	if (uState & LVIS\_SELECTED)
    		break;
    }
    if(j == i)
    {
    	MyListCtrl.SetItemState(0,LVIS\_SELECTED | LVIS\_FOCUSED | LVIS\_ACTIVATING, LVIS\_SELECTED | LVIS\_FOCUSED | LVIS\_ACTIVATING);
    	return 0;
    }
    --j; // it's the previous one
    if( j < 0)
    {
    	MyListCtrl.SetItemState(0,LVIS\_SELECTED | LVIS\_FOCUSED | LVIS\_ACTIVATING, LVIS\_SELECTED | LVIS\_FOCUSED | LVIS\_ACTIVATING);
    	return 0;
    }
    ClearSelection();
    MyListCtrl.SetItemState(j,LVIS\_SELECTED | LVIS\_FOCUSED | LVIS\_ACTIVATING, LVIS\_SELECTED | LVIS\_FOCUSED | LVIS\_ACTIVATING);
    return 0;
    

    }
    LRESULT CMyView::OnPressedNext(WPARAM, LPARAM lParam)
    {
    MyListCtrl.SetFocus();
    int i = MyListCtrl.GetItemCount();
    int j = 0;
    for(; j != i; ++j)
    {
    UINT uState = MyListCtrl.GetItemState(j, LVIS_SELECTED | LVIS_FOCUSED);
    if (uState & LVIS_SELECTED)
    break;
    }
    if(j == i)
    {
    MyListCtrl.SetItemState(0,LVIS_SELECTED | LVIS_FOCUSED | LVIS_ACTIVATING, LVIS_SELECTED | LVIS_FOCUSED | LVIS_ACTIVATING);
    return 0;
    }
    ++j; // it's the next one
    if( j >= i)
    {
    return 0;
    }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups