对于 wxWidgets 3.0.3 中的 wxtreelistctrl 示例,Getselections() 无法正常工作 [英] Getselections() is not working properly for wxtreelistctrl sample from wxWidgets 3.0.3

查看:43
本文介绍了对于 wxWidgets 3.0.3 中的 wxtreelistctrl 示例,Getselections() 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 wxWidgets 3.0.3samples 文件夹构建 treelist 项目.运行该树列表项目后,我得到了一个窗口,我从样式中选择了 2-state-checkboxesmultiple selections.然后我选择了那棵树的一些复选框.当我从 operations 点击 Dumpselections 时.现在,当调试控制器进入 OnDumpSelection() 时.在 Ondumpselection() 中,执行 getselections(),这里 getselections 应该返回被选节点的总数并进入 switch case 的默认情况.然后它应该执行 for 循环以显示每个选定的节点.但是,在调试时我看不到 numSelected 的正确值.此外,默认情况下的 for 循环未正确执行.是错误还是我做错了什么?

I am building treelist project from samples folder of wxWidgets 3.0.3. After running that treelist project, I got a window, I selected 2-state-checkboxes and multiple selections from style. then I selected some of the checkboxes of that tree. when I clicked on Dumpselections from operations. Now, while debugging controller is going into OnDumpSelection(). In Ondumpselection(), getselections() is executed, here getselections should return total no of selected nodes and go into default case of switch case. Then it should execute for loop to display every selected node. But, while debugging I am not able to see proper value of numSelected. Also, for loop from default case is not executing properly. Is it a bug or I am doing some mistake?

void MyFrame::OnItemChecked(wxTreeListEvent& event)
{
    wxTreeListItem item = event.GetItem();
    wxCheckBoxState itemCheckboxState =m_treelist->GetCheckedState(item);
    m_treelist->CheckItemRecursively(item, itemCheckboxState);
 }

推荐答案

Selection 是指被选中的项目,而不是像您认为的那样选中的复选框.没有像 GetSelections() 这样的函数来获取所有处于选中状态的项目,因为这在实践中通常不太有用:通常你会查看顶级项目,测试它是否被选中,然后看看它的孩子等等.

Selection refers to the items being selected, and not checkboxes being checked as you seem to assume. There is no function like GetSelections() for getting all the items in the checked state because this is not often useful in practice: typically you would look at the top level item, test if it is checked, then look at its children and so on.

但是你当然可以写一个 GetCheckedItems() 函数,如果你需要的话,你只需要使用 GetRootItem()GetFirstChild()GetNextSibling() 递归.

But you can, of course, write a GetCheckedItems() function if you need one, you just will have to use GetRootItem() and GetFirstChild() and GetNextSibling() recursively.

这篇关于对于 wxWidgets 3.0.3 中的 wxtreelistctrl 示例,Getselections() 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆