Free Source Code and Program Tips
Moving selection of CListCtrl
tag: CListCtrl, SetItemState, SetSelectionMark
When you try to move the item selection of a CListCtrl object, you should remember to call SetSelectionMark. If not, the program will not work as you think. It will only work once and won’t work any longer.
The reason is that even you have called SetItemState and the selection was changed in visiable, but the selection mark still keeps the old value.
The solution is to call the SetSelectionMark function after SetItemState.
Here is a short example.
void CTestListDlg::OnBtnMoveNextItem()
{
int curSel = m_list.GetSelectionMark();
int nCount = m_list.GetItemCount();
m_list.SetItemState(curSel, 0, LVIS_SELECTED);
curSel ++;
if (curSel>= nCount) curSel=0;
m_list.SetItemState(curSel, LVIS_SELECTED,LVIS_SELECTED);
m_list.SetSelectionMark(curSel);
m_list.SetFocus();
}
| Print article | This entry was posted by hamo on December 3, 2006 at 4:00 pm, and is filed under Win32/MFC. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |