I agree with David, I use that same kind of code all the time. Maybe you
"hamishd" <Hamish.Dean@gmail.com> wrote in message
news:04fd6f75-1be9-4eca-b8fb-94d4ba431325@z28g2000prd.googlegroups.com...
It doesn't seem to work. I have set:
ListView_SetExtendedListViewStyle(MyList.m_hWnd, LVS_EX_GRIDLINES |
LVS_EX_FULLROWSELECT);
and it is the report style.
Hmm, it should work. Here's the code I use all the time:
BOOL CMyListCtrl::SetFocusToItem (int i)
{
int n = GetItemCount();
if (n < 0) // no items in list
return TRUE;
// Remove selections
POSITION pos = GetFirstSelectedItemPosition();
while (pos)
{
int iItem = GetNextSelectedItem(pos);
SetItemState (iItem, 0, LVIS_SELECTED);
}
// Remove existing focus;
int iFocus = GetItemWithFocus ();
if (iFocus >= 0)
SetItemState (iFocus, 0, LVIS_FOCUSED);
// Set focus/selection
if (i < n) // valid item
SetItemState (i, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED |
LVIS_SELECTED);
return TRUE;
}
You can try to call SetFocusToItem(2) or something to see if it works and
then go from there.
-- David