SetItemState(n, LVIS_SELECTED, LVIS_SELECTED);
---------------------------------------------------------------
//获得选中
int nItem = listctrl.GetNextItem (-1, LVNI_SELECTED);
//取消选中
listctrl.SetItemState(nItem,NULL,NULL);
//设置选中
listctrl.SetItemState(nItem+1,LVNI_SELECTED,LVNI_SELECTED);
---------------------------------------------------------------
SetItemState(n, LVIS_SELECTED, LVIS_SELECTED);
---------------------------------------------------------------
m_wndList.SetFocus();
m_wndList.SetItemState(2, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED);
m_wndList.EnsureVisible(2, FALSE);
::SendMessage(m_wndList.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
---------------------------------------------------------------
以下的代码时再增加CListCtrl的行时,总是让最后一行是选中状态,看看对你有没有帮助
int nCount = m_list.GetItemCount();
if (nCount > 0)
{
m_list.EnsureVisible(nCount-1, FALSE);
m_list.SetItemState(nCount-1, LVIS_SELECTED, LVIS_SELECTED);
if ( nCount-1 > 0 )
{
m_list.SetItemState(nCount-1-1, 0, LVIS_SELECTED);
}
}
m_list.SetFocus();
---------------------------------------------------------------
SetItemState(n, LVIS_SELECTED, LVIS_SELECTED);