本文介绍了如何在 wxWidgets(C++ 代码)中使用 wxListCtrl 向第二列添加值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

int column_width = 100;

int column_width = 100;

long indx1 = alist->InsertColumn(0, L"用户名", wxLIST_FORMAT_LEFT, column_width);

long indx1 = alist->InsertColumn(0, L"User Name", wxLIST_FORMAT_LEFT, column_width);

long indx2 = alist->InsertColumn(1, L"User Id", wxLIST_FORMAT_LEFT, column_width);

long indx2 = alist->InsertColumn(1, L"User Id", wxLIST_FORMAT_LEFT, column_width);

long itemIndex1 = alist->InsertItem(indx1, L"John Smith", -1);

long itemIndex1 = alist->InsertItem(indx1, L"John Smith", -1);

alist->SetItem(indx1, 1, L"jsmith");

alist->SetItem(indx1, 1, L"jsmith");

我希望看到两列以用户名"和用户 ID"为标题,第一行的值为John Smith"和jsmith".相反,我只在 User Name 列下看到John Smith",而在 User ID 列下没有看到任何内容.这是显示结果的快照的链接:http://drop.io/agtyt6s

I expect to see two columns with User Name and User Id as heading with "John Smith" and "jsmith" as values on the first row. Instead I only see "John Smith" under column User Name but nothing under User ID column. Here is a link to the snapshot showing the result: http://drop.io/agtyt6s

谢谢!

推荐答案

这是一个显示两列的最小示例.请注意,我在 SetItem 方法中使用了 InsertItem 方法返回的索引项.

Here is a minimal sample that displays two columns. Note that I am using the index item returned by the InsertItem method in the SetItem method.

#include <wx/wx.h>

class Frame : public wxFrame
{
public:
  Frame():
    wxFrame(NULL, wxNewId(), _("App"))
  {
    wxBoxSizer * box = new wxBoxSizer(wxVERTICAL);

    wxListCtrl * listCtrl = new wxListCtrl(this, wxNewId(), wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
    listCtrl->InsertColumn(0, _("User Name"));
    listCtrl->InsertColumn(1, _("User ID"));

    long index = listCtrl->InsertItem(0, _("John Smith"));
    listCtrl->SetItem(index, 1, _("jsmith"));

    box->Add(listCtrl, 1, wxEXPAND, 0);
    SetSizer(box);
    box->SetSizeHints(this);
    Show(true);
  }
};

class App : public wxApp
{
  bool OnInit()
  {
    SetTopWindow(new Frame());
  }
};

IMPLEMENT_APP(App);

这篇关于如何在 wxWidgets(C++ 代码)中使用 wxListCtrl 向第二列添加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 07:07