Problems with sizing of wxDialog containing wxGrid 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
jamaj
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Apr 02, 2010 5:53 pm
Location: São Paulo, Brazil
Contact:

Problems with sizing of wxDialog containing wxGrid

Post by jamaj »

Dear All,

I have a wxDialog containing, among other sizers and controls, a wxGrid one. Initially, i set the wxgrid to have only 1 row and 1 col.
When i parse the file, i then add the columns and rows to accomodate the data.

The problem is to resize the wxDialog and wxGrid to acommodate the data in the wxGrid.

Code: Select all

    m_datapreview->AppendCols(c.fields,  true);
    m_datapreview->AppendRows(c.rows,  true);

    csv_free(&p);
    //exit(EXIT_SUCCESS);
    for(f=0;f<(int)c.fields;f++)
    {
        for(r=0;r<(int)c.rows;r++)
        {
            tmp = dados[r][f];
            str = wxString(tmp,wxConvUTF8);
            m_datapreview->SetCellValue(r,f,str);
        }
    }
    m_datapreview->Fit();
	this->SetClientSize(m_datapreview->GetSize());
    m_datapreview->Update();
	//this->SetSizeHints( -1, -1 );
    this->Layout();
    //this->Update();
    this->Fit();
    m_datapreview->Fit();
The above code sometime works, and sometime not. It is making me crazy. When i think its workinf, a second run of the same program gives me another gui behavior.


The most stable code that i could write is shown below:

Code: Select all

m_datapreview->Fit();
this->SetClientSize(m_datapreview->GetSize());
this->SetSizeHints( 640, 480 );
m_datapreview->Update();
this->Layout();
//this->Update();
this->Fit();
m_datapreview->Fit();
Thanks in advance for the help.
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart »

Hi,

Sizers don't always cope well when their contents dynamically change size. However there are a few other things to try:

0) Your various Fit() calls are unlikely to help.

1) If you handle size events, make sure you event.Skip();

2) Try giving the dialog a resize border (if it doesn't already have one) and resize it using the mouse. If doing this makes the layout correct, then try 3) or 4).

3) Try sending the dialog a size event. If you're using wx2.9, there's wxWindow::SendSizeEvent; if not, you'll have to create one by hand.

4) If that doesn't work, try doing
pDialog->SetSize(newsize);
where newsize increments the size by 1 unit. (If the exact size is important, you can immediately decrement it again.) Ugly, but it often works.

Regards,

David
Post Reply