Hi everyone,
I am currently working in the
Visual Studio 2008 IDE, under
Windows XP. I am using the
Unicode character set.
I am writing an application with a
CListCtrl. I am constantly updating the
CListCtrl with new information by
clearing its contents and then re-adding the updated information to it.
The problem I am having is that when I "Refresh" (update the information) the
CListCtrl it will lose the position of the selected item, so to the user it would appear to jump to the top of the list. This is an obvious consequence of redrawing the
CListCtrl.
To remedy this I have tried to implement a routine that
stores the index of the selected item before the
CListCtrl is cleared using (which functions correctly),
int nSelectedItemIndex = CListCtrl::GetNextItem(-1, LVNI_FOCUSED)
after the list has been reconstituted I then
attempt to set the state of the item at the index given by the above method with,
1 2 3 4 5 6 7 8 9 10 11 12 13
|
LVITEM lvSelector;
ZeroMemory( &lvSelector, sizeof(LVITEM) );
lvSelector.mask = LVIF_STATE;
lvSelector.iItem = nSelectedItemIndex;
lvSelector.iSubItem = 0;
lvSelector.state = LVIS_FOCUSED;
if( m_ListCtrlTest.SetItemState(nSelectedItemIndex, &lvSelector) == 0)
{
MessageBox(TEXT("Selection Failed"), TEXT("Selector"), MB_OK);
}
|
however, although the
CListCtrl::SetItemState(...) method returns success item at index nSelectedItemIndex is NOT selected (surrounded by the blue rectangle).
Have I misunderstood the documentation of this method? Can anyone suggest an alternative solution to my problem?
Thanks in advance for any help you can offer.