c++ - 我怎样才能简单地按字母顺序对 wxListCtrl 的项目进行排序?

标签 c++ wxwidgets

谁能给我一个简短的解释,说明如何按字母顺序对 wxListCtrl 的项目进行排序?我认为我找到了一种方法,但它似乎太复杂了。

提前致谢!

最佳答案

您可以按照注释中的方式设置样式,也可以使用SortItems 方法

像这样:

listCtrl->SortItems(CompareFunction, 0);

当比较函数应该类似于 strcmp 时:

int wxCALLBACK CompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr WXUNUSED(sortData))
{
  if(item1<item2) return -1;
  if(item1>item2) return 1; 
  if(item1==item2) return 0;
}

关于c++ - 我怎样才能简单地按字母顺序对 wxListCtrl 的项目进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26476869/

相关文章:

c++ - 为什么包含 .h 也会使 .cpp 源代码随之而来?

c++ - 链接 boost 库时引发 "Error while loading shared libraries",但我无法使用 root 访问权限来修复它

c++ - 在 C++11 中,如何查找并返回以给定字符串开头的字符串 vector 中的所有项?

python - wxPython 内部 : two created threads after calling app. MainLoop()

python - 如何获取 wx.ScrolledWindow 中 View 的尺寸(不受滚动条阻碍)?

c++ - c1010070 : Failed to load and parse the manifest

c++ - 通用配置代码的 Cmake 和编码风格

c++ - 如果在调用 QObject::connect() 之前发出信号,如何避免竞争?

c++ - 使用 Visual Studio 为 C++ wxwidgets 项目生成可部署二进制文件时遇到问题

C++ 在调试版本中抑制断言