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
}
27 \helpref{wxCore
}{librarieslist
}
29 \wxheading{Window styles
}
31 \begin{twocollist
}\itemsep=
0pt
32 \twocolitem{\windowstyle{wxCB
\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only.
}
33 \twocolitem{\windowstyle{wxCB
\_DROPDOWN}}{Creates a combobox with a drop-down list.
}
34 \twocolitem{\windowstyle{wxCB
\_READONLY}}{Same as wxCB
\_DROPDOWN but only the
35 strings specified as the combobox choices can be selected, it is impossible to
36 select (even from a program) a string which is not in the choices list.
}
37 \twocolitem{\windowstyle{wxCB
\_SORT}}{Sorts the entries in the list alphabetically.
}
38 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
39 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
40 is either processed internally by the control or used for navigation between
41 dialog controls). Windows only.
}
44 See also
\helpref{window styles overview
}{windowstyles
}.
46 \wxheading{Event handling
}
49 \begin{twocollist
}\itemsep=
0pt
50 \twocolitem{{\bf EVT
\_COMBOBOX(id, func)
}}{Process a wxEVT
\_COMMAND\_COMBOBOX\_SELECTED event,
51 when an item on the list is selected. Note that calling
52 \helpref{GetValue
}{wxcomboboxgetvalue
} returns the new value of selection.
}
53 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Process a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
54 when the combobox text changes.
}
55 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Process a wxEVT
\_COMMAND\_TEXT\_ENTER event,
56 when <RETURN> is pressed in the combobox (notice that the combobox must have
57 been created with
\texttt{wxTE
\_PROCESS\_ENTER} style to receive this event).
}
62 \helpref{wxListBox
}{wxlistbox
},
\helpref{wxTextCtrl
}{wxtextctrl
},
\helpref{wxChoice
}{wxchoice
},
63 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
65 \latexignore{\rtfignore{\wxheading{Members
}}}
68 \membersection{wxComboBox::wxComboBox
}\label{wxcomboboxctor
}
70 \func{}{wxComboBox
}{\void}
74 \func{}{wxComboBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
75 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
76 \param{int
}{ n =
0},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
77 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
79 \func{}{wxComboBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
80 \param{const wxString\&
}{value
},
\param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
81 \param{const wxArrayString\&
}{choices
},
\rtfsp
82 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
84 Constructor, creating and showing a combobox.
86 \wxheading{Parameters
}
88 \docparam{parent
}{Parent window. Must not be NULL.
}
90 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
92 \docparam{value
}{Initial selection string. An empty string indicates no selection.
}
94 \docparam{pos
}{Window position.
}
96 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
99 \docparam{n
}{Number of strings with which to initialise the control.
}
101 \docparam{choices
}{An array of strings with which to initialise the control.
}
103 \docparam{style
}{Window style. See
\helpref{wxComboBox
}{wxcombobox
}.
}
105 \docparam{validator
}{Window validator.
}
107 \docparam{name
}{Window name.
}
111 \helpref{wxComboBox::Create
}{wxcomboboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
113 \pythonnote{The wxComboBox constructor in wxPython reduces the
{\tt n
}
114 and
{\tt choices
} arguments are to a single argument, which is
117 \perlnote{In wxPerl there is just an array reference in place of
{\tt n
}
121 \membersection{wxComboBox::
\destruct{wxComboBox
}}\label{wxcomboboxdtor
}
123 \func{}{\destruct{wxComboBox
}}{\void}
125 Destructor, destroying the combobox.
128 \membersection{wxComboBox::Create
}\label{wxcomboboxcreate
}
130 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
131 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
132 \param{int
}{ n
},
\param{const wxString
}{choices
[]},
\rtfsp
133 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
135 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
136 \param{const wxString\&
}{value
},
\param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
137 \param{const wxArrayString\&
}{choices
},
\rtfsp
138 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
140 Creates the combobox for two-step construction. Derived classes
141 should call or replace this function. See
\helpref{wxComboBox::wxComboBox
}{wxcomboboxctor
}\rtfsp
145 \membersection{wxComboBox::CanCopy
}\label{wxcomboboxcancopy
}
147 \constfunc{bool
}{CanCopy
}{\void}
149 Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
150 Only available on Windows.
153 \membersection{wxComboBox::CanCut
}\label{wxcomboboxcancut
}
155 \constfunc{bool
}{CanCut
}{\void}
157 Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
158 Only available on Windows.
161 \membersection{wxComboBox::CanPaste
}\label{wxcomboboxcanpaste
}
163 \constfunc{bool
}{CanPaste
}{\void}
165 Returns true if the combobox is editable and there is text on the clipboard that can be pasted into the
166 text field. Only available on Windows.
169 \membersection{wxComboBox::CanRedo
}\label{wxcomboboxcanredo
}
171 \constfunc{bool
}{CanRedo
}{\void}
173 Returns true if the combobox is editable and the last undo can be redone.
174 Only available on Windows.
177 \membersection{wxComboBox::CanUndo
}\label{wxcomboboxcanundo
}
179 \constfunc{bool
}{CanUndo
}{\void}
181 Returns true if the combobox is editable and the last edit can be undone.
182 Only available on Windows.
185 \membersection{wxComboBox::Copy
}\label{wxcomboboxcopy
}
187 \func{void
}{Copy
}{\void}
189 Copies the selected text to the clipboard.
192 \membersection{wxComboBox::Cut
}\label{wxcomboboxcut
}
194 \func{void
}{Cut
}{\void}
196 Copies the selected text to the clipboard and removes the selection.
199 \membersection{wxComboBox::GetCurrentSelection
}\label{wxcomboboxgetcurrentselection
}
201 \constfunc{int
}{GetCurrentSelection
}{\void}
203 This function does the same things as
204 \helpref{wxChoice::GetCurrentSelection
}{wxchoicegetcurrentselection
} and
205 returns the item currently selected in the dropdown list if it's open or the
206 same thing as
\helpref{GetSelection
}{wxcontrolwithitemsgetselection
} otherwise.
209 \membersection{wxComboBox::GetInsertionPoint
}\label{wxcomboboxgetinsertionpoint
}
211 \constfunc{long
}{GetInsertionPoint
}{\void}
213 Returns the insertion point for the combobox's text field.
215 \textbf{Note:
} Under wxMSW, this function always returns $
0$ if the combobox
216 doesn't have the focus.
219 \membersection{wxComboBox::GetLastPosition
}\label{wxcomboboxgetlastposition
}
221 \constfunc{virtual wxTextPos
}{GetLastPosition
}{\void}
223 Returns the last position in the combobox text field.
226 \membersection{wxComboBox::GetSelection
}\label{wxcomboboxgetselection
}
228 \constfunc{void
}{GetSelection
}{\param{long *
}{from
},
\param{long *
}{to
}}
230 This is the same as
\helpref{wxTextCtrl::GetSelection
}{wxtextctrlgetselection
}
231 for the text control which is part of the combobox. Notice that this is a
232 different method from
\helpref{wxControlWithItems::GetSelection
}{wxcontrolwithitemsgetselection
}.
234 Currently this method is only implemented in wxMSW and wxGTK.
237 \membersection{wxComboBox::GetValue
}\label{wxcomboboxgetvalue
}
239 \constfunc{wxString
}{GetValue
}{\void}
241 Returns the current value in the combobox text field.
244 \membersection{wxComboBox::Paste
}\label{wxcomboboxpaste
}
246 \func{void
}{Paste
}{\void}
248 Pastes text from the clipboard to the text field.
251 \membersection{wxComboBox::Redo
}\label{wxcomboboxredo
}
253 \func{void
}{Redo
}{\void}
255 Redoes the last undo in the text field. Windows only.
258 \membersection{wxComboBox::Replace
}\label{wxcomboboxreplace
}
260 \func{void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{text
}}
262 Replaces the text between two positions with the given text, in the combobox text field.
264 \wxheading{Parameters
}
266 \docparam{from
}{The first position.
}
268 \docparam{to
}{The second position.
}
270 \docparam{text
}{The text to insert.
}
273 \membersection{wxComboBox::Remove
}\label{wxcomboboxremove
}
275 \func{void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
277 Removes the text between the two positions in the combobox text field.
279 \wxheading{Parameters
}
281 \docparam{from
}{The first position.
}
283 \docparam{to
}{The last position.
}
286 \membersection{wxComboBox::SetInsertionPoint
}\label{wxcomboboxsetinsertionpoint
}
288 \func{void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
290 Sets the insertion point in the combobox text field.
292 \wxheading{Parameters
}
294 \docparam{pos
}{The new insertion point.
}
297 \membersection{wxComboBox::SetInsertionPointEnd
}\label{wxcomboboxsetinsertionpointend
}
299 \func{void
}{SetInsertionPointEnd
}{\void}
301 Sets the insertion point at the end of the combobox text field.
304 \membersection{wxComboBox::SetSelection
}\label{wxcomboboxsetselection
}
306 \func{void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
308 Selects the text between the two positions, in the combobox text field.
310 \wxheading{Parameters
}
312 \docparam{from
}{The first position.
}
314 \docparam{to
}{The second position.
}
316 \pythonnote{This method is called
{\tt SetMark
} in wxPython,
{\tt SetSelection
}
318 \helpref{wxControlWithItems::SetSelection
}{wxcontrolwithitemssetselection
}.
}
321 \membersection{wxComboBox::SetValue
}\label{wxcomboboxsetvalue
}
323 \func{void
}{SetValue
}{\param{const wxString\&
}{text
}}
325 Sets the text for the combobox text field.
327 {\bf NB:
} For a combobox with
{\tt wxCB
\_READONLY} style the string must be in
328 the combobox choices list, otherwise the call to SetValue() is ignored.
330 \wxheading{Parameters
}
332 \docparam{text
}{The text to set.
}
335 \membersection{wxComboBox::Undo
}\label{wxcomboboxundo
}
337 \func{void
}{Undo
}{\void}
339 Undoes the last edit in the text field. Windows only.