Fix re-creating wxComboBox in widgets sample
To preserve layout, old wxComboBox should be replaced with the new one in the same location in the sizer. So we need to create a new combo box first, put in the sizer and only after that the old combo box can be deleted.
This commit is contained in:
@@ -417,6 +417,8 @@ void ComboboxWidgetsPage::Reset()
|
|||||||
|
|
||||||
void ComboboxWidgetsPage::CreateCombo()
|
void ComboboxWidgetsPage::CreateCombo()
|
||||||
{
|
{
|
||||||
|
wxCHECK_RET( m_combobox, "No combo box exists" );
|
||||||
|
|
||||||
int flags = GetAttrs().m_defaultFlags;
|
int flags = GetAttrs().m_defaultFlags;
|
||||||
|
|
||||||
if ( m_chkSort->GetValue() )
|
if ( m_chkSort->GetValue() )
|
||||||
@@ -446,31 +448,27 @@ void ComboboxWidgetsPage::CreateCombo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxArrayString items;
|
wxArrayString items;
|
||||||
if ( m_combobox )
|
|
||||||
{
|
|
||||||
unsigned int count = m_combobox->GetCount();
|
unsigned int count = m_combobox->GetCount();
|
||||||
for ( unsigned int n = 0; n < count; n++ )
|
for ( unsigned int n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
items.Add(m_combobox->GetString(n));
|
items.Add(m_combobox->GetString(n));
|
||||||
}
|
}
|
||||||
|
int selItem = m_combobox->GetSelection();
|
||||||
|
|
||||||
m_sizerCombo->Detach( m_combobox );
|
wxComboBox* newCb = new wxComboBox(this, wxID_ANY, wxEmptyString,
|
||||||
delete m_combobox;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString,
|
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
0, NULL,
|
items,
|
||||||
flags);
|
flags);
|
||||||
|
|
||||||
unsigned int count = items.GetCount();
|
if ( selItem != wxNOT_FOUND )
|
||||||
for ( unsigned int n = 0; n < count; n++ )
|
newCb->SetSelection(selItem);
|
||||||
{
|
|
||||||
m_combobox->Append(items[n]);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sizerCombo->Add(m_combobox, 0, wxGROW | wxALL, 5);
|
m_sizerCombo->Replace(m_combobox, newCb);
|
||||||
m_sizerCombo->Layout();
|
m_sizerCombo->Layout();
|
||||||
|
|
||||||
|
delete m_combobox;
|
||||||
|
m_combobox = newCb;
|
||||||
|
m_combobox->SetId(ComboPage_Combo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user