Version: 2.9.4
Public Member Functions
wxComboBox Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/combobox.h>

Inheritance diagram for wxComboBox:

Detailed Description

A combobox is like a combination of an edit control and a listbox.

It can be displayed as static list with editable or read-only text field; or a drop-down list with text field; or a drop-down list without a text field depending on the platform and presence of wxCB_READONLY style.

A combobox permits a single selection only. Combobox items are numbered from zero.

If you need a customized combobox, have a look at wxComboCtrl, wxOwnerDrawnComboBox, wxComboPopup and the ready-to-use wxBitmapComboBox.

Please refer to wxTextEntry documentation for the description of methods operating with the text entry part of the combobox and to wxItemContainer for the methods operating with the list of strings. Notice that at least under MSW wxComboBox doesn't behave correctly if it contains strings differing in case only so portable programs should avoid adding such strings to this control.

Styles

This class supports the following styles:

Events emitted by this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxCommandEvent& event)

Event macros for events emitted by this class:

Library:  wxCore
Category:  Controls

Appearance:
wxMSW appearancewxGTK appearancewxMac appearance
wxMSW appearancewxGTK appearancewxMac appearance
参照:
wxListBox, wxTextCtrl, wxChoice, wxCommandEvent

Public Member Functions

 wxComboBox ()
 Default constructor.
 wxComboBox (wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxComboBoxNameStr)
 Constructor, creating and showing a combobox.
 wxComboBox (wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxComboBoxNameStr)
 Constructor, creating and showing a combobox.
virtual ~wxComboBox ()
 Destructor, destroying the combobox.
virtual int GetCurrentSelection () const
 Returns the item being selected right now.
virtual long GetInsertionPoint () const
 Same as wxTextEntry::GetInsertionPoint().
bool IsEmpty () const
 IsEmpty() is not available in this class.
bool IsListEmpty () const
 Returns true if the list of combobox choices is empty.
bool IsTextEmpty () const
 Returns true if the text of the combobox is empty.
virtual void SetSelection (long from, long to)
 Same as wxTextEntry::SetSelection().
virtual void SetValue (const wxString &text)
 Sets the text for the combobox text field.
virtual void Popup ()
 Shows the list box portion of the combo box.
virtual void Dismiss ()
 Hides the list box portion of the combo box.
virtual int GetSelection () const
 Returns the index of the selected item or wxNOT_FOUND if no item is selected.
virtual void GetSelection (long *from, long *to) const
 Gets the current selection span.
virtual void SetSelection (int n)
 Sets the selection to the given item n or removes the selection entirely if n == wxNOT_FOUND.
virtual int FindString (const wxString &s, bool bCase=false) const
 Finds an item whose label matches the given string.
virtual wxString GetString (unsigned int n) const
 Returns the label of the item with the given index.
virtual wxString GetStringSelection () const
 Gets the text currently selected in the control.
virtual void SetString (unsigned int n, const wxString &text)
 Changes the text of the specified combobox item.
virtual unsigned int GetCount () const
 Returns the number of items in the control.
bool Create (wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=(const wxString *) NULL, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxComboBoxNameStr)
 Creates the combobox for two-step construction.
bool Create (wxWindow *parent, wxWindowID id, const wxString &value, const wxPoint &pos, const wxSize &size, const wxArrayString &choices, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxComboBoxNameStr)
 Creates the combobox for two-step construction.

List of all members.


Constructor & Destructor Documentation

wxComboBox::wxComboBox ( )

Default constructor.

wxComboBox::wxComboBox ( wxWindow parent,
wxWindowID  id,
const wxString value = wxEmptyString,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
int  n = 0,
const wxString  choices[] = NULL,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxComboBoxNameStr 
)

Constructor, creating and showing a combobox.

Parameters:
parentParent window. Must not be NULL.
idWindow identifier. The value wxID_ANY indicates a default value.
valueInitial selection string. An empty string indicates no selection. Notice that for the controls with wxCB_READONLY style this string must be one of the valid choices if it is not empty.
posWindow position. If wxDefaultPosition is specified then a default position is chosen.
sizeWindow size. If wxDefaultSize is specified then the window is sized appropriately.
nNumber of strings with which to initialise the control.
choicesAn array of strings with which to initialise the control.
styleWindow style. See wxComboBox.
validatorWindow validator.
nameWindow name.

wxPerl Note: Not supported by wxPerl.

参照:
Create(), wxValidator
wxComboBox::wxComboBox ( wxWindow parent,
wxWindowID  id,
const wxString value,
const wxPoint pos,
const wxSize size,
const wxArrayString choices,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxComboBoxNameStr 
)

Constructor, creating and showing a combobox.

Parameters:
parentParent window. Must not be NULL.
idWindow identifier. The value wxID_ANY indicates a default value.
valueInitial selection string. An empty string indicates no selection.
posWindow position.
sizeWindow size. If wxDefaultSize is specified then the window is sized appropriately.
choicesAn array of strings with which to initialise the control.
styleWindow style. See wxComboBox.
validatorWindow validator.
nameWindow name.

wxPerl Note: Use an array reference for the choices parameter.

参照:
Create(), wxValidator
virtual wxComboBox::~wxComboBox ( ) [virtual]

Destructor, destroying the combobox.


Member Function Documentation

bool wxComboBox::Create ( wxWindow parent,
wxWindowID  id,
const wxString value = wxEmptyString,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
int  n = 0,
const wxString  choices[] = (const wxString *) NULL,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxComboBoxNameStr 
)

Creates the combobox for two-step construction.

Derived classes should call or replace this function. See wxComboBox() for further details.

Reimplemented in wxBitmapComboBox.

bool wxComboBox::Create ( wxWindow parent,
wxWindowID  id,
const wxString value,
const wxPoint pos,
const wxSize size,
const wxArrayString choices,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxComboBoxNameStr 
)

Creates the combobox for two-step construction.

Derived classes should call or replace this function. See wxComboBox() for further details.

Reimplemented in wxBitmapComboBox.

virtual void wxComboBox::Dismiss ( ) [virtual]

Hides the list box portion of the combo box.

Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.

Notice that calling this function will generate a wxEVT_COMMAND_COMBOBOX_CLOSEUP event except under wxOSX where generation of this event is not supported at all.

Since:
2.9.1
virtual int wxComboBox::FindString ( const wxString string,
bool  caseSensitive = false 
) const [virtual]

Finds an item whose label matches the given string.

Parameters:
stringString to find.
caseSensitiveWhether search is case sensitive (default is not).
Returns:
The zero-based position of the item, or wxNOT_FOUND if the string was not found.

Reimplemented from wxItemContainerImmutable.

virtual unsigned int wxComboBox::GetCount ( ) const [virtual]

Returns the number of items in the control.

参照:
IsEmpty()

Implements wxItemContainerImmutable.

virtual int wxComboBox::GetCurrentSelection ( ) const [virtual]

Returns the item being selected right now.

This function does the same things as wxChoice::GetCurrentSelection() and returns the item currently selected in the dropdown list if it's open or the same thing as wxControlWithItems::GetSelection() otherwise.

virtual long wxComboBox::GetInsertionPoint ( ) const [virtual]

Same as wxTextEntry::GetInsertionPoint().

注:
Under wxMSW, this function always returns 0 if the combobox doesn't have the focus.

Reimplemented from wxTextEntry.

virtual int wxComboBox::GetSelection ( ) const [virtual]

Returns the index of the selected item or wxNOT_FOUND if no item is selected.

Returns:
The position of the current selection.
注意:
This method can be used with single selection list boxes only, you should use wxListBox::GetSelections() for the list boxes with wxLB_MULTIPLE style.
参照:
SetSelection(), GetStringSelection()

Implements wxItemContainerImmutable.

virtual void wxComboBox::GetSelection ( long *  from,
long *  to 
) const [virtual]

Gets the current selection span.

If the returned values are equal, there was no selection. Please note that the indices returned may be used with the other wxTextCtrl methods but don't necessarily represent the correct indices into the string returned by GetValue() for multiline controls under Windows (at least,) you should use GetStringSelection() to get the selected text.

Parameters:
fromThe returned first position.
toThe returned last position.

wxPerl Note: In wxPerl this method takes no parameters and returns a 2-element list (from, to).

Reimplemented from wxTextEntry.

virtual wxString wxComboBox::GetString ( unsigned int  n) const [virtual]

Returns the label of the item with the given index.

Parameters:
nThe zero-based index.
Returns:
The label of the item or an empty string if the position was invalid.

Implements wxItemContainerImmutable.

virtual wxString wxComboBox::GetStringSelection ( ) const [virtual]

Gets the text currently selected in the control.

If there is no selection, the returned string is empty.

Reimplemented from wxTextEntry.

bool wxComboBox::IsEmpty ( ) const [virtual]

IsEmpty() is not available in this class.

This method is documented here only to notice that it can't be used with this class because of the ambiguity between the methods with the same name inherited from wxItemContainer and wxTextEntry base classes.

Because of this, any attempt to call it results in a compilation error and you should use either IsListEmpty() or IsTextEmpty() depending on what exactly do you want to test.

Reimplemented from wxTextEntry.

bool wxComboBox::IsListEmpty ( ) const

Returns true if the list of combobox choices is empty.

Use this method instead of (not available in this class) IsEmpty() to test if the list of items is empty.

Since:
2.9.3
bool wxComboBox::IsTextEmpty ( ) const

Returns true if the text of the combobox is empty.

Use this method instead of (not available in this class) IsEmpty() to test if the text currently entered into the combobox is empty.

Since:
2.9.3
virtual void wxComboBox::Popup ( ) [virtual]

Shows the list box portion of the combo box.

Currently this method is implemented in wxMSW, wxGTK and wxOSX/Cocoa.

Notice that calling this function will generate a wxEVT_COMMAND_COMBOBOX_DROPDOWN event except under wxOSX where generation of this event is not supported at all.

Since:
2.9.1
virtual void wxComboBox::SetSelection ( int  n) [virtual]

Sets the selection to the given item n or removes the selection entirely if n == wxNOT_FOUND.

Note that this does not cause any command events to be emitted nor does it deselect any other items in the controls which support multiple selections.

Parameters:
nThe string position to select, starting from zero.
参照:
SetString(), SetStringSelection()

Implements wxItemContainerImmutable.

virtual void wxComboBox::SetSelection ( long  from,
long  to 
) [virtual]

Same as wxTextEntry::SetSelection().

Reimplemented from wxTextEntry.

virtual void wxComboBox::SetString ( unsigned int  n,
const wxString text 
) [virtual]

Changes the text of the specified combobox item.

Notice that if the item is the currently selected one, i.e. if its text is displayed in the text part of the combobox, then the text is also replaced with the new text.

Implements wxItemContainerImmutable.

virtual void wxComboBox::SetValue ( const wxString text) [virtual]

Sets the text for the combobox text field.

Notice that this method will generate a wxEVT_COMMAND_TEXT_UPDATED event, use wxTextEntry::ChangeValue() if this is undesirable.

注:
For a combobox with wxCB_READONLY style the string must be in the combobox choices list, otherwise the call to SetValue() is ignored. This is case insensitive.
Parameters:
textThe text to set.

Reimplemented from wxTextEntry.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines