If one adds widgets in the columns and rows of a wxGridBagSizer, GetRows() and GetCols() return 0 and 1 untill Layout() is called after which they return the true numbers:
wxGridBagSizer* gridBagSizer = new wxGridBagSizer();
gridBagSizer->Add(5,5,
wxGBPosition(0,0));
gridBagSizer->Add(new wxStaticText(this,wxID_ANY, "Hello world!"),
wxGBPosition(1,1), wxGBSpan(1,1), EXPAND);
gridBagSizer->Add(5,5,
wxGBPosition(2,2));
gridBagSizer->AddGrowableCol(0); gridBagSizer->AddGrowableRow(0);
gridBagSizer->AddGrowableCol(wxGridBagSizer->GetCols()); gridBagSizer->AddGrowableRow(wxGridBagSizer->GetRows());
// The above does not work because before calling gridBagSizer->Layouy() // the number of rows is always 0 and the number of columns 1 gridBagSizer->GetRows(); // reports 0 gridBagSizer->GetCols(); // reports 1
gridBagSizer->Layout();
gridBagSizer->GetRows(); // reports 3 gridBagSizer->GetCols(); // reports 3