troubleshooting Question

SetItemState() isn't getting the item drawn as selected until some other event happens

Avatar of _Scotch_
_Scotch_ asked on
System Programming
7 Comments1 Solution713 ViewsLast Modified:
I'm trying to make an item in a list control show selected.  I am using LVS_OWNERDATA so I can't use SetItem() but I can use SetItemState().  The list control is embedded in a CFormView which is embedded in a pane of a splitter which is part of a mdi child.

The call works, but not correctly.  The item does not show up selected unless I:

1) Occlude the window, then bring it back
2) Touch the horizontal or vertical scroll bars -- I don't even have to scroll the item out of view.
3) Minimize the window and bring it back (I see the item go selected before the window actually gets minimized)

Here's the call and all of the things I've tried to make windows get the item to show selected.  They all work in that for example SetHotItem() makes the item hot, invalidate causes the window to flicker, etc... But my item still doesn't appear selected until I physically interact with the window in some way...

      if (m_nLastSearchPosition != -1)  {
            V->m_ListControl.EnsureVisible(m_nLastSearchPosition, FALSE);
            V->m_ListControl.SetItemState(m_nLastSearchPosition, LVIS_SELECTED, LVIS_SELECTED|LVIS_FOCUSED);
//            V->m_ListControl.Scroll(CSize(100,20));
//            V->m_ListControl.Scroll(CSize(0,20));
//            V->m_ListControl.RedrawItems(m_nLastSearchPosition, m_nLastSearchPosition);
//            V->m_ListControl.Update(m_nLastSearchPosition);
//            V->m_ListControl.SetCheck(m_nLastSearchPosition);
//            V->m_ListControl.SetHotItem(m_nLastSearchPosition);
//            V->m_ListControl.Invalidate();
//            V->GetParent()->Invalidate();
//            V->GetParent()->GetParent()->Invalidate();

Thoughts ?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros