Search code examples
c++wxwidgets

how to change the wxDataViewListCtrl fit to wxPanel


my GUIFrame has a Panel function, firstof alli wanna expand DataView window, but when i add wxSize to wxDataViewListCtrl* listctrl = new wxDataViewListCtrl(this, -1, wxDefaultPosition, wxSize(350, 600)) then just Panel change and Dataview is not change;

enter image description here

I wanna ask how to change the wxDataViewListCtrl fit to wxPanel.

 GUIFrame::GUIFrame(wxWindow* parent, int id, const wxString& title,
    const wxPoint& pos,
    const wxSize& size)
    : wxFrame(parent, id, title, pos, size)
{
    wxWindowUpdateLocker noUpdates(this);
wxMenuBar* m_pMenuBar = new wxMenuBar();
    // File Menu
    wxMenu* m_pFileMenu = new wxMenu();
    m_pFileMenu->Append(wxID_OPEN, _T("&Open"));
    m_pFileMenu->Append(wxID_SAVE, _T("&Save"));
    m_pFileMenu->AppendSeparator();
    m_pFileMenu->Append(wxID_EXIT, _T("&Quit"));
    m_pMenuBar->Append(m_pFileMenu, _T("&File"));
    // About menu
    wxMenu* m_pHelpMenu = new wxMenu();
    m_pHelpMenu->Append(wxID_ABOUT, _T("&About"));
    m_pMenuBar->Append(m_pHelpMenu, _T("&Help"));

    this->SetMenuBar(m_pMenuBar);

wxPanel* dataViewPanel = new DataViewPanel(this, -1);

}

//////////////////////////////////////////////////////////////////////////
//! DataView Panel ////////////////////////////////////////////////////////
GUIFrame::DataViewPanel::DataViewPanel(wxWindow* parent, int ID)
    : wxPanel(parent, ID)
{
    wxDataViewListCtrl* listctrl = new wxDataViewListCtrl(this, -1);
//wxDefaultPosition, wxSize(350, 600));
    listctrl->AppendToggleColumn("");
    listctrl->AppendTextColumn("Text");
    wxVector<wxVariant> data;
    data.push_back(wxVariant(true));
    data.push_back(wxVariant("row 1"));
    listctrl->AppendItem(data);
    data.clear();
    data.push_back(wxVariant(false));
    data.push_back(wxVariant("row 3"));
    listctrl->AppendItem(data);
}

Solution

  • The best way is to use a wxSizer.
    Set a sizer to your panel. Add the wxDataViewListCtrl to the sizer.

    Another way is catching the EVT_SIZE all windows trigger.
    Handle it for your panel. In this handler get the size of the panel an set it to the wxDataViewListCtrl if you want it to fill the whole panel.