CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 1999
    Posts
    14

    CListCtrl, Why doesn't this work?

    I am trying to select all the items in a list control, but the below code doesn't seem to work... Can anyone tell me what I am missing?

    int num_items = m_List.GetItemCount();


    for (int i = 0; i < num_items; i++)
    m_List.SetItem(i, 0, LVIF_STATE, NULL, 0, LVIS_SELECTED, LVIS_SELECTED, 0);




    Thanks,
    Jaime



  2. #2
    Join Date
    May 1999
    Posts
    116

    Re: CListCtrl, Why doesn't this work?

    Is only the last one being selected? If so, you dont have multiple select turned on.

    You could also tryfor ( int i=0; i<m_list.GetItemCount(); i++ )
    m_list.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);

    This works for me.


  3. #3
    Join Date
    May 1999
    Posts
    14

    Re: CListCtrl, Why doesn't this work?

    I figured out what it was...
    When the "Select All" button was pressed, my code executed and did what it was supposed to do, but the results did not show up because the ListCtrl lost focus...

    SO, i just did list.SetFocus() and all is well now!

    Thanks,
    Jaime


  4. #4
    Join Date
    May 1999
    Posts
    116

    Re: CListCtrl, Why doesn't this work?

    A nice trick here is to turn on "Show Selection Always" (in the resource editor - append the style in the Create call). Then even when th list control does no have the focus, the items will show up selected.


  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: CListCtrl, Why doesn't this work?

    why did it lose focus???

    Sally


  6. #6
    Join Date
    Apr 1999
    Posts
    32

    Re: CListCtrl, Why doesn't this work?

    The list control lost focus because a button was clicked ("Select All" in this case). When this happens the button gains the input focus; hence the list control loses it.

    --
    Daren Chandisingh

  7. #7
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: CListCtrl, Why doesn't this work?

    but if you click on another control, with that comes the idea that you have transferred control to that control, in this case the button, I beleive that the best user interface response is to keep the focus as it is and to use SHOW ALWAYS.

    Sally


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