Thread: CListCtrl

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Massachusetts
    Posts
    22
    Rep Power
    0

    CListCtrl


    I am using visual c++ 6 w/ MFC. I have a list box and I have a CListCtrl variable assigned to it. Once the user selects an item in the list box I highlight it. I want it to stay highlighted even when the user clicks in the list box but not on an item. I am not sure of how to do this. Any help is appreciated.

    Thanks,
    Chris
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    >>I want it to stay highlighted even when the user clicks in the list box but not on an item.

    By default that is the user selecting another item. Unless they hold down the shift or contol key windows processes as if they are selecting a new item.

    How else does the user 'de-select' an item?


    Look at the LV styles and extended styles

    LVS_EX_FULLROWSELECT //needs you to enable the ext styles

    LVS_SHOWSELALWAYS


    you could always go to owner draw

    LVS_OWNERDRAWFIXED

    and process the drawitem msg's. Then just colour the areas using a pen you create.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Massachusetts
    Posts
    22
    Rep Power
    0
    I always want the user to have an item highlighted in the list box, unless they delete a highlighted item, or purge the entire list contense.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Massachusetts
    Posts
    22
    Rep Power
    0
    OK, I wrote soem code to find the last selected item. When the new item is selected I need to know how to unselect the old item. I use m_ctrlTransList.SetItemState(iLastSelect, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED); to select the item. Is there an easy way to un-select the item using this function?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Massachusetts
    Posts
    22
    Rep Power
    0
    I figured it out here is the code:

    void COTGTransmitUtilityDlg::OnItemchangedTransmitList(NMHDR* pNMHDR, LRESULT* pResult)
    {
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    int itemCount = m_ctrlTransList.GetItemCount();
    int index = m_ctrlTransList.GetNextItem(-1, LVNI_SELECTED);

    if (index >= 0) // Valid item selected
    {
    CMenu* mmenu = GetMenu();
    CMenu* submenu = mmenu->GetSubMenu(0);
    submenu->EnableMenuItem(IDR_FILE_DELETE_OTG, MF_BYCOMMAND | MF_ENABLED);
    submenu->EnableMenuItem(ID_FILE_STOPTRANSMITTING, MF_BYCOMMAND | MF_ENABLED);
    *pResult = 0;
    iLastSelect = index;
    }
    else // selecting the item that has focus / user clicked in the list ctrl but not on an item.
    { // the item that has been un-highlighted by clicking in the list ctrl but not on a
    //valid item still hass focus...
    int x = 0;
    while (x < entryCount)
    {
    if ( m_ctrlTransList.GetItemState(x, LVIS_FOCUSED) )
    { // Item has focus - now highlighting it
    m_ctrlTransList.SetItemState(x, LVIS_SELECTED, LVIS_SELECTED);
    break;
    }
    x++;
    }
    m_ctrlTransList.EnsureVisible(x, FALSE);
    }
    }

    m_ctrlTransList is my ListCtrl

IMN logo majestic logo threadwatch logo seochat tools logo