[英]How to set an item in CListCtrl as selected?
ClistCtrl is set to single selection & single column in report view with no header. ClistCtrl 在没有标题的报告视图中设置为单选和单列。
I have tried SetItemState(0,LVIS_SELECTED,LVIF_STATE)
and我试过
SetItemState(0,LVIS_SELECTED,LVIF_STATE)
和SetSelectionMark(int index)
but these don't work. SetSelectionMark(int index)
但这些不起作用。
you also need to call SetSelectionMark after updating the item states.您还需要在更新项目状态后调用 SetSelectionMark。
SetItemState(prev_item, ~LVIS_SELECTED, LVIS_SELECTED);
SetItemState(new_selected_item, LVIS_SELECTED, LVIS_SELECTED);
SetSelectionMark(new_selected_item);
使用 SetItemState(0, LVIS_SELECTED, LVIS_SELECTED) 突出显示,使用 SetItemState(0, ~LVIS_SELECTED, LVIS_SELECTED) 取消突出显示。
只需设置属性->外观->始终显示选择为真
I think there is an undocumented feature of the SetItemState
function where you can pass -1
as its nItem
argument to make the function act on all items.我认为
SetItemState
函数有一个未记录的功能,您可以将-1
作为其nItem
参数传递,以使该函数作用于所有项目。
So, if you only want to select only one , I can suggest:所以,如果你只想选择一个,我可以建议:
SetItemState(-1, 0, LVIS_SELECTED);
SetItemState(index, LVIS_SELECTED, LVIS_SELECTED);
UPDATE:更新:
(after seeing http://www.verycomputer.com/417_11fcb075491b88c9_1.htm#p3 ) (看到http://www.verycomputer.com/417_11fcb075491b88c9_1.htm#p3 后)
The SetItemState
function sends the LVM_SETITEMSTATE
message, and the nItem=-1 feature is documented on the message's reference documentation as its wParam
argument. SetItemState
函数发送LVM_SETITEMSTATE
消息,并且 nItem=-1 功能作为其wParam
参数记录在消息的参考文档中。
If you wont set selected item in OnInitialDialog you mast use this code:如果您不会在 OnInitialDialog 中设置所选项目,则必须使用以下代码:
m_pSPSMapList->EnsureVisible(nItem, FALSE);
m_pSPSMapList->SetFocus();
m_pSPSMapList->SetItemState(nItem, LVIS_FOCUSED | LVIS_SELECTED,
LVIS_FOCUSED | LVIS_SELECTED);
return FALSE; // OnInitialDialog necessarily must return false
Provided that the index of the item fo be selected is w_nCurIdx , Use the following code假设要选择的item的索引是w_nCurIdx ,使用如下代码
m_pSPSMapList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
m_pSPSMapList.SetItemState(w_nCurIdx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.