1 \section{\class{wxComboBox
}}\label{wxcombobox
}
3 A combobox is like a combination of an edit control and a listbox. It can be
4 displayed as static list with editable or read-only text field; or a drop-down list with
5 text field; or a drop-down list without a text field.
7 A combobox permits a single selection only. Combobox items are numbered from zero.
9 If you need a customized combobox, have a look at
\helpref{wxComboCtrl
}{wxcomboctrl
},
10 \helpref{wxOwnerDrawnComboBox
}{wxownerdrawncombobox
},
\helpref{wxComboPopup
}{wxcombopopup
}
11 and the ready-to-use
\helpref{wxBitmapComboBox
}{wxbitmapcombobox
}.
13 \wxheading{Derived from
}
15 \helpref{wxControlWithItems
}{wxcontrolwithitems
}\\
16 \helpref{wxControl
}{wxcontrol
}\\
17 \helpref{wxWindow
}{wxwindow
}\\
18 \helpref{wxEvtHandler
}{wxevthandler
}\\
19 \helpref{wxObject
}{wxobject
}
21 \wxheading{Include files
}
25 \wxheading{Window styles
}
27 \begin{twocollist
}\itemsep=
0pt
28 \twocolitem{\windowstyle{wxCB
\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only.
}
29 \twocolitem{\windowstyle{wxCB
\_DROPDOWN}}{Creates a combobox with a drop-down list.
}
30 \twocolitem{\windowstyle{wxCB
\_READONLY}}{Same as wxCB
\_DROPDOWN but only the
31 strings specified as the combobox choices can be selected, it is impossible to
32 select (even from a program) a string which is not in the choices list.
}
33 \twocolitem{\windowstyle{wxCB
\_SORT}}{Sorts the entries in the list alphabetically.
}
34 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
35 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
36 is either processed internally by the control or used for navigation between
37 dialog controls). Windows only.
}
40 See also
\helpref{window styles overview
}{windowstyles
}.
42 \wxheading{Event handling
}
45 \begin{twocollist
}\itemsep=
0pt
46 \twocolitem{{\bf EVT
\_COMBOBOX(id, func)
}}{Process a wxEVT
\_COMMAND\_COMBOBOX\_SELECTED event,
47 when an item on the list is selected. Note that calling
48 \helpref{GetValue
}{wxcomboboxgetvalue
} returns the new value of selection.
}
49 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Process a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
50 when the combobox text changes.
}
51 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Process a wxEVT
\_COMMAND\_TEXT\_ENTER event,
52 when <RETURN> is pressed in the combobox.
}
57 \helpref{wxListBox
}{wxlistbox
},
\helpref{wxTextCtrl
}{wxtextctrl
},
\helpref{wxChoice
}{wxchoice
},
58 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
60 \latexignore{\rtfignore{\wxheading{Members
}}}
63 \membersection{wxComboBox::wxComboBox
}\label{wxcomboboxctor
}
65 \func{}{wxComboBox
}{\void}
69 \func{}{wxComboBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
70 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
71 \param{int
}{ n =
0},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
72 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
74 \func{}{wxComboBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
75 \param{const wxString\&
}{value
},
\param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
76 \param{const wxArrayString\&
}{choices
},
\rtfsp
77 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
79 Constructor, creating and showing a combobox.
81 \wxheading{Parameters
}
83 \docparam{parent
}{Parent window. Must not be NULL.
}
85 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
87 \docparam{value
}{Initial selection string. An empty string indicates no selection.
}
89 \docparam{pos
}{Window position.
}
91 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
94 \docparam{n
}{Number of strings with which to initialise the control.
}
96 \docparam{choices
}{An array of strings with which to initialise the control.
}
98 \docparam{style
}{Window style. See
\helpref{wxComboBox
}{wxcombobox
}.
}
100 \docparam{validator
}{Window validator.
}
102 \docparam{name
}{Window name.
}
106 \helpref{wxComboBox::Create
}{wxcomboboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
108 \pythonnote{The wxComboBox constructor in wxPython reduces the
{\tt n
}
109 and
{\tt choices
} arguments are to a single argument, which is
112 \perlnote{In wxPerl there is just an array reference in place of
{\tt n
}
116 \membersection{wxComboBox::
\destruct{wxComboBox
}}\label{wxcomboboxdtor
}
118 \func{}{\destruct{wxComboBox
}}{\void}
120 Destructor, destroying the combobox.
123 \membersection{wxComboBox::Create
}\label{wxcomboboxcreate
}
125 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
126 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
127 \param{int
}{ n
},
\param{const wxString
}{choices
[]},
\rtfsp
128 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
130 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
131 \param{const wxString\&
}{value
},
\param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
132 \param{const wxArrayString\&
}{choices
},
\rtfsp
133 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
135 Creates the combobox for two-step construction. Derived classes
136 should call or replace this function. See
\helpref{wxComboBox::wxComboBox
}{wxcomboboxctor
}\rtfsp
140 \membersection{wxComboBox::CanCopy
}\label{wxcomboboxcancopy
}
142 \constfunc{bool
}{CanCopy
}{\void}
144 Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
145 Only available on Windows.
148 \membersection{wxComboBox::CanCut
}\label{wxcomboboxcancut
}
150 \constfunc{bool
}{CanCut
}{\void}
152 Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
153 Only available on Windows.
156 \membersection{wxComboBox::CanPaste
}\label{wxcomboboxcanpaste
}
158 \constfunc{bool
}{CanPaste
}{\void}
160 Returns true if the combobox is editable and there is text on the clipboard that can be pasted into the
161 text field. Only available on Windows.
164 \membersection{wxComboBox::CanRedo
}\label{wxcomboboxcanredo
}
166 \constfunc{bool
}{CanRedo
}{\void}
168 Returns true if the combobox is editable and the last undo can be redone.
169 Only available on Windows.
172 \membersection{wxComboBox::CanUndo
}\label{wxcomboboxcanundo
}
174 \constfunc{bool
}{CanUndo
}{\void}
176 Returns true if the combobox is editable and the last edit can be undone.
177 Only available on Windows.
180 \membersection{wxComboBox::Copy
}\label{wxcomboboxcopy
}
182 \func{void
}{Copy
}{\void}
184 Copies the selected text to the clipboard.
187 \membersection{wxComboBox::Cut
}\label{wxcomboboxcut
}
189 \func{void
}{Cut
}{\void}
191 Copies the selected text to the clipboard and removes the selection.
194 \membersection{wxComboBox::GetCurrentSelection
}\label{wxcomboboxgetcurrentselection
}
196 \constfunc{int
}{GetCurrentSelection
}{\void}
198 This function does the same things as
199 \helpref{wxChoice::GetCurrentSelection
}{wxchoicegetcurrentselection
} and
200 returns the item currently selected in the dropdown list if it's open or the
201 same thing as
\helpref{GetSelection
}{wxcontrolwithitemsgetselection
} otherwise.
204 \membersection{wxComboBox::GetInsertionPoint
}\label{wxcomboboxgetinsertionpoint
}
206 \constfunc{long
}{GetInsertionPoint
}{\void}
208 Returns the insertion point for the combobox's text field.
210 \textbf{Note:
} Under wxMSW, this function always returns $
0$ if the combobox
211 doesn't have the focus.
214 \membersection{wxComboBox::GetLastPosition
}\label{wxcomboboxgetlastposition
}
216 \constfunc{virtual wxTextPos
}{GetLastPosition
}{\void}
218 Returns the last position in the combobox text field.
221 \membersection{wxComboBox::GetValue
}\label{wxcomboboxgetvalue
}
223 \constfunc{wxString
}{GetValue
}{\void}
225 Returns the current value in the combobox text field.
228 \membersection{wxComboBox::Paste
}\label{wxcomboboxpaste
}
230 \func{void
}{Paste
}{\void}
232 Pastes text from the clipboard to the text field.
235 \membersection{wxComboBox::Redo
}\label{wxcomboboxredo
}
237 \func{void
}{Redo
}{\void}
239 Redoes the last undo in the text field. Windows only.
242 \membersection{wxComboBox::Replace
}\label{wxcomboboxreplace
}
244 \func{void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{text
}}
246 Replaces the text between two positions with the given text, in the combobox text field.
248 \wxheading{Parameters
}
250 \docparam{from
}{The first position.
}
252 \docparam{to
}{The second position.
}
254 \docparam{text
}{The text to insert.
}
257 \membersection{wxComboBox::Remove
}\label{wxcomboboxremove
}
259 \func{void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
261 Removes the text between the two positions in the combobox text field.
263 \wxheading{Parameters
}
265 \docparam{from
}{The first position.
}
267 \docparam{to
}{The last position.
}
270 \membersection{wxComboBox::SetInsertionPoint
}\label{wxcomboboxsetinsertionpoint
}
272 \func{void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
274 Sets the insertion point in the combobox text field.
276 \wxheading{Parameters
}
278 \docparam{pos
}{The new insertion point.
}
281 \membersection{wxComboBox::SetInsertionPointEnd
}\label{wxcomboboxsetinsertionpointend
}
283 \func{void
}{SetInsertionPointEnd
}{\void}
285 Sets the insertion point at the end of the combobox text field.
288 \membersection{wxComboBox::SetSelection
}\label{wxcomboboxsetselection
}
290 \func{void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
292 Selects the text between the two positions, in the combobox text field.
294 \wxheading{Parameters
}
296 \docparam{from
}{The first position.
}
298 \docparam{to
}{The second position.
}
300 \pythonnote{This method is called
{\tt SetMark
} in wxPython,
{\tt SetSelection
}
302 \helpref{wxControlWithItems::SetSelection
}{wxcontrolwithitemssetselection
}.
}
305 \membersection{wxComboBox::SetValue
}\label{wxcomboboxsetvalue
}
307 \func{void
}{SetValue
}{\param{const wxString\&
}{text
}}
309 Sets the text for the combobox text field.
311 {\bf NB:
} For a combobox with
{\tt wxCB
\_READONLY} style the string must be in
312 the combobox choices list, otherwise the call to SetValue() is ignored.
314 \wxheading{Parameters
}
316 \docparam{text
}{The text to set.
}
319 \membersection{wxComboBox::Undo
}\label{wxcomboboxundo
}
321 \func{void
}{Undo
}{\void}
323 Undoes the last edit in the text field. Windows only.