How to clean, populate and refresh a wxPanel? Topic is solved

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
Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

How to clean, populate and refresh a wxPanel?

Post by Sunsawe »

Hi,

So as the title says, I would like to clean a wxPanel; meaning, erasing every child it may have. Then I would like to assign it a new sizer with and new "children". Finally I would like to update the view.
This is the code I use:

Code: Select all

//page is the panel
page->DestroyChildren();

fgs = new wxFlexGridSizer(0,2,1,1);
fgs->AddGrowableCol(1);

fgs->Add( new wxStaticText(page,wxID_ANY,wxT("Name :")));
fgs->Add( new wxStaticText(page,wxID_ANY,wxT("Test Failure")),1,wxEXPAND,0);

if(condition)
{
fgs->Add( new wxStaticText(page,wxID_ANY,wxT("Level :")));
fgs->Add( new wxStaticText(page,wxID_ANY,wxT("Critical Failure")),1,wxEXPAND,0);
}

page->SetSizer(fgs);
page->Refresh();
With this, every new element is added to the very first line of the panel (so the texts are on top of each others). But when I resize the window, everything gets in order. The lines and columns are respected and the previous elements are gone.
I tried to replace the Refresh method by Update, but the result was the same, meaning, like when they were actually not called at all.

So does DestroyChildren eliminates previous sizers as well?
Could someone explain what I am doing wrong?

Thank you
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

Try hiding all children before the call to destroy them.

What I think happens is this: the old windows will be destroyed at idle time, and the first idle event will be received after all other code there (including Refresh) is executed. So you only see the difference at the next Refresh event.
Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

Post by Sunsawe »

I am sorry but how do you hide the children of a wxWindow?

I try to hide the complete panel before modifying it and re-show it afterwards. It did not change anything.
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,

You could try a Layout() call at the end of that code.

But why do this? It would be easier to delete the panel itself and create a new one. And easier still if you subclass wxPanel, then put the above code in its ctor.

Regards,

David
Sunsawe
Experienced Solver
Experienced Solver
Posts: 54
Joined: Tue Jan 30, 2007 5:04 pm

Post by Sunsawe »

Actually, I don't want to destroy and recreate the panel because it can come from different places and already a part of a complex module.
It seems simpler to just clean it than to find out where it is coming from and in which sizers it is already included then replace the new panel in that place.

But thank you for your answer, it did the trick.
Post Reply