Add Scroll boxes around wxgrid

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
guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Add Scroll boxes around wxgrid

Post by guzzi_jones » Mon Mar 24, 2014 12:08 am

How do i add scroll boxes around a wxgrid.
I have a wxgrid on my frame, but when the results are longer than the display i have no way to scroll down.
Thanks as always very helpful.

I attached a pic of what i explained.

I tried to add the scroll attributes, but it did not help
Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(516,218), wxVSCROLL|wxHSCROLL, _T("ID_GRID1"));
Attachments
screenshot.png
wxgrid
screenshot.png (26.78 KiB) Viewed 1680 times

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

Re: Add Scroll boxes around wxgrid

Post by doublemax » Mon Mar 24, 2014 2:13 pm

Usually you don't have to do anything to make the scrollbars appear. They should be displayed automatically if the client size of the grid is too small to display its content.

From the screenshot it looks like the grid is big enough, but leaving the parent window at the bottom. This shouldn't happen if you're using sizers.

Maybe you can post some more code.
Use the source, Luke!

guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Re: Add Scroll boxes around wxgrid

Post by guzzi_jones » Mon Mar 24, 2014 11:48 pm

editchain::editchain(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{


//(*Initialize(editchain)
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer1;
wxFlexGridSizer* FlexGridSizer1;

Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("id"));
SetClientSize(wxDefaultSize);
Move(wxDefaultPosition);
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
FlexGridSizer1 = new wxFlexGridSizer(3, 2, 0, 0);
StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Chain Code"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
FlexGridSizer1->Add(StaticText1, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
TextCode = new wxTextCtrl(Panel1, ID_TEXTCODE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCODE"));
FlexGridSizer1->Add(TextCode, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("Chain Name"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
FlexGridSizer1->Add(StaticText2, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
TextName = new wxTextCtrl(Panel1, ID_Name, wxEmptyString, wxDefaultPosition, wxSize(293,27), 0, wxDefaultValidator, _T("ID_Name"));
FlexGridSizer1->Add(TextName, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Chain License Type"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
FlexGridSizer1->Add(StaticText3, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
Choice1 = new wxChoice(Panel1, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE1"));
FlexGridSizer1->Add(Choice1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText4 = new wxStaticText(Panel1, ID_STATICTEXT4, _("Chain Trade Channel"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
FlexGridSizer1->Add(StaticText4, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
Choice2 = new wxChoice(Panel1, ID_CHOICE2, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE2"));
FlexGridSizer1->Add(Choice2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText5 = new wxStaticText(Panel1, ID_STATICTEXT5, _("Chain Food Type"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
FlexGridSizer1->Add(StaticText5, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
Choice3 = new wxChoice(Panel1, ID_CHOICE3, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE3"));
FlexGridSizer1->Add(Choice3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticText6 = new wxStaticText(Panel1, ID_STATICTEXT6, _("Chain Account Type"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
FlexGridSizer1->Add(StaticText6, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
Choice4 = new wxChoice(Panel1, ID_CHOICE4, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE4"));
FlexGridSizer1->Add(Choice4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer1->Add(0,0,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Add = new wxButton(Panel1, ID_Add, _("Add"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_Add"));
FlexGridSizer1->Add(Add, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(516,209), wxVSCROLL|wxHSCROLL, _T("ID_GRID1"));
BoxSizer2->Add(Grid1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer1->Add(BoxSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Delete = new wxButton(Panel1, ID_Delete, _("Delete"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_Delete"));
FlexGridSizer1->Add(Delete, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer1->Add(0,0,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(FlexGridSizer1);
FlexGridSizer1->Fit(Panel1);
FlexGridSizer1->SetSizeHints(Panel1);
BoxSizer1->Add(Panel1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);

Connect(ID_TEXTCODE,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&editchain::OnTextCodeTextupdated);
Connect(ID_Name,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&editchain::OnTextNameTextupdated);
Connect(ID_Add,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&editchain::OnAddClick);
Connect(wxID_ANY,wxEVT_INIT_DIALOG,(wxObjectEventFunction)&editchain::OnInit);
//*)
//


}

guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Re: Add Scroll boxes around wxgrid

Post by guzzi_jones » Tue Mar 25, 2014 12:59 am

better yet:
here is the svn link
[edit] [deleted]
Last edited by guzzi_jones on Tue Mar 25, 2014 2:49 am, edited 1 time in total.

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

Re: Add Scroll boxes around wxgrid

Post by doublemax » Tue Mar 25, 2014 2:13 am

As i can't just paste this code into a minimal sample to test it myself, i'll make a first blind guess:

Code: Select all

Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(516,209), wxVSCROLL|wxHSCROLL, _T("ID_GRID1"));
BoxSizer2->Add(Grid1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
Use wxEXPAND instead of wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL for the sizer flags.

And BTW: I assume this code is generated by some GUI editor? Most sizer flags are illogical. E.g having both wxALIGN_CENTER_HORIZONTAL and wxALIGN_CENTER_VERTICAL in a wxBoxSizer doesn't make sense. Same goes for the combination of wxEXPAND with wxALIGN_CENTER_HORIZONTAL or wxALIGN_CENTER_VERTICAL depending on the direction of the sizer.
Use the source, Luke!

guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Re: Add Scroll boxes around wxgrid

Post by guzzi_jones » Tue Mar 25, 2014 2:18 am

doublemax wrote:As i can't just paste this code into a minimal sample to test it myself, i'll make a first blind guess:

Code: Select all

Grid1 = new wxGrid(Panel1, ID_GRID1, wxDefaultPosition, wxSize(516,209), wxVSCROLL|wxHSCROLL, _T("ID_GRID1"));
BoxSizer2->Add(Grid1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
Use wxEXPAND instead of wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL for the sizer flags.

And BTW: I assume this code is generated by some GUI editor? Most sizer flags are illogical. E.g having both wxALIGN_CENTER_HORIZONTAL and wxALIGN_CENTER_VERTICAL in a wxBoxSizer doesn't make sense. Same goes for the combination of wxEXPAND with wxALIGN_CENTER_HORIZONTAL or wxALIGN_CENTER_VERTICAL depending on the direction of the sizer.
You are correct!. I am using codeblocks with wxwidgets/wxsmith add ons.
Is there a really good tutorial i can pick up to learn wxwidgets for a newb. I have been teaching myself c++ for a few months now, but i am still learning. Thanks.

guzzi_jones
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sun Dec 08, 2013 3:50 am

Re: Add Scroll boxes around wxgrid

Post by guzzi_jones » Tue Mar 25, 2014 2:46 am

aahhh. my bad.
after i drew the wxgrid i had:
Grid1->AutoSize();

which created a new size for the grid. All good now!

Post Reply