更新时间:2023-11-15 10:50:58
这是一个显示两列的最小示例.请注意,我在 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);