wxEditableListBox - border issue

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

wxEditableListBox - border issue

Post by deepti » Tue Sep 04, 2018 7:00 pm

Hi,

I have a wxEditableListBox, which looks like the screenshot below. Is there a way the border drawn can be changed? The box containing the New, Edit and Delete buttons looks like it can be edited! But in reality, it is just for displaying the label.
Can i change that border to a non-3D border? Please help!
editablelistbox.jpg
editablelistbox.jpg (11.89 KiB) Viewed 374 times

User avatar
doublemax
Moderator
Moderator
Posts: 15083
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxEditableListBox - border issue

Post by doublemax » Tue Sep 04, 2018 7:09 pm

Looking into the source code, there is definitely no easy or "official" way to do it, the border style is hard coded.

The only way would be to find the panel among the children of the control and try to change its border style. Possible, but i'm not sure if it's worth the effort.

Or you could just change it in the wxWidgets source and rebuild.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2517
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxEditableListBox - border issue

Post by PB » Tue Sep 04, 2018 8:27 pm

I think "hacking" would be much easier then modifying the library source code and all things coming from diverging from the official wxWidgets source. It is just a couple lines of code and should be quite safe. Whether it's worth it...
editablelbox.png
editablelbox.png (7.21 KiB) Viewed 361 times

Code: Select all

#include <wx/wx.h>
#include <wx/editlbox.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(600, 400))
    {       
        const wxString label = "First one";
       
        wxPanel* mainPanel = new wxPanel(this);       
        wxBoxSizer* mainPanelSizer = new wxBoxSizer(wxVERTICAL);

        wxEditableListBox* elb = new wxEditableListBox(mainPanel, wxID_ANY, label);               
        wxWindow* labelWnd = FindWindowByLabel(label, elb);

        if ( labelWnd && dynamic_cast<wxStaticText*>(labelWnd) )
        {
           wxPanel* labelWndParent = dynamic_cast<wxPanel*>(labelWnd->GetParent());

           if ( labelWndParent && labelWndParent->HasFlag(wxBORDER_SUNKEN) )
           {               
               labelWndParent->ToggleWindowStyle(wxBORDER_SUNKEN);
               labelWndParent->ToggleWindowStyle(wxBORDER_SIMPLE);                               
           }               
        }
        mainPanelSizer->Add(elb, 1, wxALL | wxEXPAND, 10);

        elb = new wxEditableListBox(mainPanel, wxID_ANY, "Second one");               
        mainPanelSizer->Add(elb, 1, wxALL | wxEXPAND, 10);
     
        mainPanel->SetSizer(mainPanelSizer);         
    }   
};

class MyApp : public wxApp
{
public:   
   bool OnInit()
   {
        (new MyFrame)->Show();
        return true;
   }
}; wxIMPLEMENT_APP(MyApp);

deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxEditableListBox - border issue

Post by deepti » Wed Sep 05, 2018 4:30 am

Superb! I love this forum...makes life so much easier.
Thanks a lot PB, and to all of you who help us with wxWidgets!

Post Reply