【问题标题】:How to clear all selections in a wxListBox (with wxLB_MULTIPLE)?如何清除 wxListBox 中的所有选择(使用 wxLB_MULTIPLE)?
【发布时间】:2021-03-10 02:25:19
【问题描述】:

如何清除样式为 wxLB_MULTIPLE 的 wxListBox 中的所有选择?

wxControlWithItems::SetSelection()wxControlWIthItems::SetStringSelection() 都不起作用。 他们只选择通过的项目,但不会取消选择文档中所述的任何其他项目:

请注意,这不会导致发出任何命令事件,也不会导致 它是否取消选择控件中支持的任何其他项目 多选。

【问题讨论】:

    标签: c++ listbox selection wxwidgets


    【解决方案1】:

    我会使用wxListBox::GetSelections 其次是wxListBox::Deselect,因为没有取消全选方法。

    【讨论】:

    • 抱歉回复晚了。我在 较旧的 wxWidgets 2.8 版本中的common\listctrlcmn.cpp 中找到了wxListBox::DeselectAll()(它的实现方式与您所说的相同)。但是更新之后就再也找不到了!无论如何,我为 Windows 系统找到了一种更简单的方法 -> 看看我的答案!
    【解决方案2】:

    平台无关方法

    正如 SteveL 所说,您必须在循环中使用 wxListBox::GetSelections()wxListBox::Deselect()

    wxArrayInt selections;
    int count = m_listBox->GetSelections(selections);
    
    for ( int i=0; i<count; i++ )
    {
      m_listBox->Deselect(selections[i]);
    }
    

    适用于 Windows 系统的 ListBox_SetSel 宏

    您可以使用 Windows API 中的宏 ListBox_SetSel

    对于这个函数,你必须包括Windowsx.hwx/msw/winundef.h,当然:

    #include <Windowsx.h>
    #include <wx/msw/winundef.h>
    
    // ...
    HWND hListBox = (HWND)m_listBox->GetHandle();
    ListBox_SetSel(hListBox, false, -1);
    

    【讨论】:

      【解决方案3】:

      m_listBox->清除(); 这个方法对我有用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-05
        • 1970-01-01
        • 1970-01-01
        • 2012-07-17
        • 2020-11-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多