CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: List Control

  1. #1
    Join Date
    May 1999
    Location
    JAPAN
    Posts
    11

    List Control

    Hi,
    In the list view control, if you delete an item how do set back the focus onto any other item in the list.
    thanx

    giri

  2. #2
    Join Date
    May 1999
    Location
    Reading, England
    Posts
    28

    Re: List Control

    The code is simple, but you must handle 2 cases:

    * the deleted item being the first in the list - you then select the next one.

    * the deleted item is somewehere else - selecting the previous item is probably best.

    For the code fragment, assume m_nSelectedItem was the index of the deleted item.

    ...
    if(m_nSelectedItem == 0)
    {
    // Select the next item in the list
    LVITEM lvItem;
    lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
    lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;

    m_ListCtrl.SetFocus();
    m_ListCtrl.SetItemState(m_nSelectedItem, &lvItem);
    }
    else
    {
    // Select the previous item in the list
    LVITEM lvItem;
    lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
    lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;

    m_ListCtrl.SetFocus();
    m_ListCtrl.SetItemState(m_nSelectedItem - 1, &lvItem);
    }

    NB: _you_ may not need to use SetFocus()

    Stu


  3. #3
    Join Date
    Apr 1999
    Posts
    26

    Re: List Control

    I have a search function in my application which is looking from the CListCtrl. I have done the SetItemState and managed to highlight and focus on the item.
    My problem is how can I make the CListCtrl to scroll to the focused item's page? Thanks.


  4. #4
    Join Date
    May 1999
    Location
    Reading, England
    Posts
    28

    Re: List Control

    This surprises me - I assume you don't have access to VC help or even the entire MSDN library at http://msdn.microsoft.com/library/default.htm ?! ;-)

    Try CListCtrl::EnsureVisible()


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured