Re: Listview control question. by r_z_aret
r_z_aret
Wed Oct 29 14:46:18 CST 2003
On 28 Oct 2003 14:18:23 -0800, kaz@ashi.footprints.net (Kaz Kylheku)
wrote:
>To make an application faster and more responsive, I switched a list view
>control to virtual. I'm not doing custom drawing, just owner data. Everything
>works great except that I'm having trouble preserving one behavior of the
>program. In the handler for a particular message which tells the dialog to
>update the list data, I have logic which tries to select the last item and
>bring it into view:
>
> // WTL syntax:
>
> numItems = Compute();
> lastItem = numItems - 1;
>
> m_list.SetItemCount(numItems);
> m_list.SetItemState(lastItem, LVIS_FOCUSED | LVIS_SELECTED,
> LVIS_FOCUSED | LVIS_SELECTED);
> m_list.EnsureVisible(lastItem, TRUE);
>
>Trouble is, the item is not selected and does not scroll into view. What's
>more, the control seems to remember the previous selection. For instance
>suppose that item 3 was previously selected (manually, by the user) and the
>above tries to select the last item, say 23. The control will not scroll down
>to show item 23. Moreover, if the user tries to move the cursor down, then
>suddenly item 4 will be selected and focused.
>
>Is there some trick to make this work with a virtual list view control? Maybe
>it's sensitive as to when in the painting cycle these calls are made?
I've never tried making a list view virtual. But I suspect folks who
have might want you to clarify whether the code worked before you made
the list view virtual.
The following is my code for non-virtual list views. I don't know
whether it will work with virtual list views. If nothing else, the
references in the comments might help.
BOOL centerSelection( int nChoice ) const // Centers
{ return ListView_EnsureVisible( m_hWnd, nChoice, FALSE );
} // 9 Oct 03 (4.0.0.28)
// ----------------------------------------------------------
// centerChoice
// Call centerSelection, then select specified line
BOOL ClsPFListView::centerChoice( int nChoice ) const
{
nChoice = max( 0, nChoice );
nChoice = min( nChoice, (GetNCount() -1) ); //lint !e666 side
effect & second arg
if (centerSelection( nChoice ))
{
#if 0
Click();
#else
// 9 Oct 03 (4.0.0.28)
#if 1
// See KnowledgeBase article Q131284
ListView_SetItemState( GetHwnd(), nChoice, (LVIS_SELECTED |
LVIS_FOCUSED), 0x000F );
#else
// Also, thread called "ListViews" in
powersoft.public.watcom_c_c++.general
// around 3 March 2003
// Also, 24 Jul 1999 contribution from Phaedrus to thread
called
// "How To Select Item in ListView?" in
comp.os.ms-windows.programmer.tools.mfc
ListView_SetItemState( GetHwnd(), nChoice, LVIS_SELECTED |
LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
#endif
ASSERT( ListView_GetItemState( GetHwnd(), nChoice,
LVIS_SELECTED ) > 0 );
ASSERT( ListView_GetItemState( GetHwnd(), nChoice,
LVIS_FOCUSED ) > 0 );
VERIFY( ListView_Update( GetHwnd(), nChoice ) );
#endif
return TRUE;
}
else
return FALSE;
} // centerChoice
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com