Re: Unable to select/click items in wxListBox
Maarten Bent <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I see two issues in the code you provided.
First, you create mainPanel twice, in the initializer list and again in
the body of the constructor. I would remove it from the initializer list.
I suspect the panel(s) and list are overlapping, so you are clicking on
the panel instead of the list.
Second, the panel/sizer structure seems wrong. You are adding both the
panel and the listbox as children of the main frame (of 'this').
I think you want the listbox as child of the panel, like this:
mainPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition,
wxSize(600, 600));
s1 = new wxBoxSizer(wxVERTICAL);
m_tgeListBox = new wxListBox(mainPanel, wxID_ANY,
wxDefaultPosition, wxSize(300, 200));
s1->Add(m_tgeListBox, 1, wxEXPAND);
mainPanel->SetSizer(s1);
Since you expand the listbox to fill the entire frame, you could also
omit the panel entirely:
s1 = new wxBoxSizer(wxVERTICAL);
m_tgeListBox = new wxListBox(this, wxID_ANY, wxDefaultPosition,
wxSize(300, 200));
s1->Add(m_tgeListBox, 1, wxEXPAND);
SetSizer(s1);
Maarten
On 8-9-2023 07:21, Eva L wrote:
> Hello. I'm having trouble selecting and/or clicking items in wxListBox
> only if it's part of a sizer. I basically want the wxListBox to expand
> with the window.
>
> Here is the code:
> *MainFrame::MainFrame(const wxString& title)
> : wxFrame(nullptr, wxID_ANY, title),
> mainPanel(new wxPanel(this, wxID_ANY, wxDefaultPosition,
> wxSize(300, 200)))
> {
> Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnClose, this);
>
> SetFont(GetFont().Scale(1.5));
>
> mainPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(600,
> 600));
> s1 = new wxBoxSizer(wxVERTICAL);
>
> m_tgeListBox = new wxListBox(this, wxID_ANY, wxDefaultPosition,
> wxSize(300, 200));
>
> s1->Add(m_tgeListBox, 1, wxEXPAND);
> SetSizerAndFit(s1);
> }*
> *
> *
> Why is this happening and how can it be solved?
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google
> Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/wx-users/f8a6f6d1-e914-416f-8b6b-dd7c4c0c4408n%40googlegroups.com
> <https://groups.google.com/d/msgid/wx-users/f8a6f6d1-e914-416f-8b6b-dd7c4c0c4408n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/94e147b7-9232-4e96-90af-d8a723ad1afb%40gmail.com.