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

    listviewctrl (report) selecting & highlighting

    Hey,

    I'm using these lines to scroll & highlight to a specific item in my list... it *scrolls*,
    but the line is not being selected/focues/highlighted. All examples from the
    "selection"-part from the listview control topic here at codeguru don't work
    either...

    (I have set LVM_SETEXTENDEDLISTVIEWSTYLE & LVS_EX_FULLROWSELECT
    before and it works great when clicking into the view)


    m_liste.EnsureVisible( pos, NULL);
    m_liste.SetItemState( pos, LVIS_SELECTED, LVIS_SELECTED);
    m_liste.Update( pos);




    I tried these other SetItemState-Calls - they all don't work (they all return a nonzero-value, so they
    SEEM to do something, but nothing actually happens):


    m_liste.SetItemState( pos, LVIS_SELECTED | LVIS_FOCUSED, LVIF_STATE);
    m_liste.SetItemState( pos, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
    m_liste.SetItemState( pos, LVIS_SELECTED, LVIF_STATE);




    Any idea, anyone?

    Thank you.


    -.-.-

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

    Re: listviewctrl (report) selecting & highlighting

    Hi,

    Hmm, you seem to be doing the right thing. The correct SetItemState() is:

    m_liste.SetItemState( pos, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);



    The only thing I can think of is that the list control is losing focus, so you not seeing your selection. Are you executing the 'selection' code as a result of pressing a button on the same dialog for example?

    Try setting the list style LVS_SHOWSELALWAYS ("Show selection always" on the control properties) - this way you'll be able to see the selected item even if the list hasn't got focus...

    As a last resort, try m_liste.SetFocus() before calling SetItemState()

    Stuart



  3. #3
    Join Date
    May 1999
    Posts
    16

    Re: listviewctrl (report) selecting & highlighting

    Hi,

    you were right - the control needs the focus... so a simple SetFocus() did the job! :-)

    Thanks!



    -.-.-

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