| Version: 3.2.2

Public Member Functions | List of all members
wxPersistentComboBox Class Reference

`#include <wx/persist/combobox.h>`

Inheritance diagram for wxPersistentComboBox:
[legend]

## Detailed Description

Persistence adapter for wxComboBox.

This adapter saves and restores the items of wxComboBox. A persistent combobox can be used to preserve history of user entries.

Example of using it:

// Suppose you need to ask the user to select their favourite Linux
// distribution, for some reason:
wxComboBox* combo = new wxComboBox(this, wxID_ANY);
if ( !wxPersistentRegisterAndRestore(combo, "distribution") )
{
// Seed it with some default contents.
combo->Append("Debian");
combo->Append("Fedora");
combo->Append("Ubuntu");
}
// Optionally, you might want to restore the last used entry:
combo->SetSelection(0);
wxComboBox
A combobox is like a combination of an edit control and a listbox.
Definition: combobox.h:85
wxComboBox::SetSelection
virtual void SetSelection(long from, long to)
Same as wxTextEntry::SetSelection().
wxItemContainer::Append
int Append(const wxString &item)
Appends item into the control.
wxID_ANY
@ wxID_ANY
Any id: means that we don't care about the id, whether when installing an event handler or when creat...
Definition: defs.h:597
wxPersistentRegisterAndRestore
bool wxPersistentRegisterAndRestore(T *obj, const wxString &name=wxString())
A shorter synonym for wxPersistenceManager::RegisterAndRestore().

Since
  3.1.5

## Public Member Functions

| wxPersistentComboBox (wxComboBox *combobox)
| Constructor. More...
virtual void | Save () const
| Save the current items and value. More...
virtual bool | Restore ()
| Restore the combobox items. More...
Public Member Functions inherited from wxPersistentWindow< wxComboBox >
| wxPersistentWindow (WindowType *win)
| Constructor for a persistent window object. More...
WindowType * | Get () const
virtual wxString | GetName () const
| Implements the base class pure virtual method using wxWindow::GetName(). More...
Public Member Functions inherited from wxPersistentObject
| wxPersistentObject (void *obj)
| Constructor takes the object which we're associated with. More...
virtual | ~wxPersistentObject ()
| Trivial but virtual destructor. More...
void * | GetObject () const
| Return the associated object. More...
virtual wxString | GetKind () const =0
| Returns the string uniquely identifying the objects supported by this adapter. More...

## Additional Inherited Members

Public Types inherited from wxPersistentWindow< wxComboBox >
typedef wxComboBox | WindowType
| The type of the associated window. More...
Protected Member Functions inherited from wxPersistentObject
template<typename T >
bool | SaveValue (const wxString &name, T value) const
| Save the specified value using the given name. More...
template<typename T >
bool | RestoreValue (const wxString &name, T *value)
| Restore a value saved by SaveValue(). More...

## Constructor & Destructor Documentation

## ◆ wxPersistentComboBox()

wxPersistentComboBox::wxPersistentComboBox | ( | wxComboBox * | combobox | ) |

explicit

Constructor.

Parameters

  combobox | The associated combobox.

## Member Function Documentation

## ◆ Restore()

virtual bool wxPersistentComboBox::Restore | ( |  | ) |

virtual

Restore the combobox items.

This function doesn't change the current combobox value, you need to call `SetSelection(0)` explicitly, after verifying that the combobox is not empty using its IsListEmpty() method, if you want to restore the last used value automatically. Otherwise the user can always do it by opening the combobox and selecting it manually.

Implements wxPersistentObject.

## ◆ Save()

virtual void wxPersistentComboBox::Save | ( |  | ) | const

virtual

Save the current items and value.

The current control value is saved as the first item, so that calling `SetSelection(0)` when the control is created the next time will restore the value which was last used. If the current value is the same as one of the existing items, this item is moved to the front of the list, instead of being added again.

If the current value is empty, it is not saved at all.

At most 10 items are saved, if the combobox has more than 10 items, or exactly 10 items and the current value is different from all of them, the items beyond the tenth one are discarded.

Implements wxPersistentObject.