简体   繁体   English

CListCtrl - 如何启用多选

[英]CListCtrl - how to enable multiple selection

I am creating a MFC application for Windows Mobile and don't know how to enable multiple selection for List Control (CListCtrl).我正在为 Windows Mobile 创建 MFC 应用程序,但不知道如何为列表控件 (CListCtrl) 启用多项选择。 In properties panel Single Selection is set to False but still can't select multiple items.在属性面板中单选设置为 False 但仍然无法选择多个项目。

Any idea?有什么想法吗?

I have never targeted Windows Mobile but you might try the following:我从未针对 Windows Mobile,但您可以尝试以下操作:

list.ModifyStyle(LVS_SINGLESEL, 0); list.ModifyStyle(LVS_SINGLESEL, 0);

如果您希望以编程方式执行此操作,则 CWnd 基础的 ModifyStyle 方法将起作用(请参阅 Diego 的帖子),或者如果您将控件放置在对话框上,则可以在资源编辑器中定义属性。

All ListView window styles are defined in the CommCtrl.h header file.所有 ListView 窗口样式都在CommCtrl.h头文件中定义。 Check this page on Microsoft's website.在 Microsoft 网站上查看此页面

The default setting for a ListView control allows multiple selections. ListView 控件的默认设置允许进行多项选择。 If you need to allow only single selection from the list, then use below code:如果您只需要允许从列表中进行单项选择,请使用以下代码:

m_ListControl.ModifyStyle(NULL, LVS_SINGLESEL, 0); 

m_ListControl is the variable for your List Control. m_ListControl是列表控件的变量。 You can many other styles mentioned on above page.您可以在上面提到的许多其他样式。

Here is another example:这是另一个例子:

ListView_SetExtendedListViewStyle(::GetDlgItem(m_hWnd, IDC_LIST1), LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM