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

Thread: CListCtrl help!

  1. #1
    Join Date
    Apr 2007
    Posts
    19

    CListCtrl help!

    Hy everyone!
    I have a CListCtrl in my dialog that has a lot of items, so list is scrollable,
    i have just 1 problem, when user wants to search an item in the list, if a match is found it notifies the user via MessageBox and highlights the item in the list, i do this all successfuly, but user has to scroll down to the item to see it is selected.

    How can i make that when item is found that list scrolls itself to that item?
    Please help, thanks!

  2. #2
    Join Date
    May 2006
    Location
    Mumbai, India
    Posts
    292

    Re: CListCtrl help!

    Hi !

    You can use CListCtrl::SetHotItem using index to set item as selected...

    Thanks ,

  3. #3
    Join Date
    Jul 2005
    Location
    E: 120°.6, N: 31°.3′
    Posts
    795

    Re: CListCtrl help!

    1) Find the position of the item you already searched.
    2) Take a look at how many row in your list control if without scroll.
    3) According the row you got , using scroll if exceed row without using scroll, you may call scroll.

    Hope I already understand what you are writting.
    Little by little one goes far
    Keep moving.......!
    Nothing is impossible !

  4. #4
    Join Date
    Aug 2002
    Posts
    879

    Re: CListCtrl help!

    You can use the EnsureVisible() function for this.
    http://msdn2.microsoft.com/en-us/lib...sf(VS.80).aspx

    Use the search function ('EnsureVisible CListCtrl') for more examples.

  5. #5
    Join Date
    Apr 2007
    Posts
    19

    Re: CListCtrl help!

    But it just highlights the item, list does not scroll to that item,
    i need a way so that the list scrolls to that item... Can u help?

  6. #6
    Join Date
    Apr 2007
    Posts
    19

    Re: CListCtrl help!

    Thanks blueday54555, it works!

  7. #7
    Join Date
    May 2005
    Posts
    364

    Re: CListCtrl help!

    How is the selected item highlighted.

    i used this

    pl->SetHotItem(num - 2);
    pl->SetSelectionMark(num - 2);
    pl->SetCheck(num - 2, TRUE);
    pl->EnsureVisible(num - 2, FALSE);
    but its not highlighting the selected one
    Dan

  8. #8
    Join Date
    Jul 2005
    Location
    E: 120°.6, N: 31°.3′
    Posts
    795

    Re: CListCtrl help!

    Double check your program first, if question, you'd better think it over for why first , then you will learn some more.
    Little by little one goes far
    Keep moving.......!
    Nothing is impossible !

  9. #9
    Join Date
    Aug 2002
    Posts
    879

    Re: CListCtrl help!

    You have to use SetItemState()
    e.g.
    Code:
    ................
    list->SetFocus();
    list->SetSelectionMark(index);
    list->SetItemState(index,LVIS_SELECTED, LVIS_SELECTED);
    list->EnsureVisible(index, FALSE);
    ...................

  10. #10
    Join Date
    May 2005
    Posts
    364

    Re: CListCtrl help!

    Thanks
    Dan

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