wxListCtrl简单使用

本文介绍了如何在C++和wxWidgets框架下使用wxListCtrl组件。通过核心代码展示,详细解释了如何初始化、添加条目以及交互操作,为开发者提供了清晰的wxListCtrl使用指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述

核心代码:

Simple::Simple(const wxString& title) :wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(450,400))
{
    wxPanel* panel = new wxPanel(this, wxID_ANY);
    //wxListCtrl* listCtrl = new wxListCtrl(panel, wxID_ANY, wxPoint(50, 50), wxDefaultSize, wxLC_REPORT | wxDOUBLE_BORDER);

    m_item_list = new wxListCtrl(panel, wxID_ANY, wxPoint(10,10), wxDefaultSize, wxLC_REPORT);
    m_item_list->SetForegroundColour(wxColour(0, 255, 0));
    m_item_list->SetBackgroundColour(wxColour(0, 0, 0));

    // Add first column       
    wxListItem col0;
    col0.SetId(0);
    col0.SetText(_("Foo"));
    col0.SetWidth(100);
    m_item_list->InsertColumn(0, col0);

    // Add second column
    wxListItem col1;
    col1.SetId(1);
    col1.SetText(_("Name"));
    col1.SetWidth(100);
    m_item_list->InsertColumn(1, col1);

    // Add third column     
    wxListItem col2;
    col2.SetId(2);
    col2.SetText(_("Comments"));
    col2.SetWidth(100);
    m_item_list->InsertColumn(2, col2);

    wxButton* button = new wxButton(panel, wxID_ANY, "add",wxPoint(314,9));
    button->Bind(wxEVT_BUTTON, &Simple::OnButtonClick, this);

    this->Centre();
}


Simple::~Simple()
{
}

void Simple::OnButtonClick(wxCommandEvent& event)
{
    static int i = 0;
    m_item_list->InsertItem(i, "");
    m_item_list->SetItem(i, 0, "ID");
    m_item_list->SetItem(i, 1, "worker");
    m_item_list->SetItem(i, 2, "value");
    ++i;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值