]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/listbox.tex
added wxLocale::IsAvailable() (extended patch 1547191)
[wxWidgets.git] / docs / latex / wx / listbox.tex
CommitLineData
a660d684
KB
1\section{\class{wxListBox}}\label{wxlistbox}
2
3A listbox is used to select one or more of a list of strings. The
4strings are displayed in a scrolling box, with the selected string(s)
5marked in reverse video. A listbox can be single selection (if an item
6is selected, the previous selection is removed) or multiple selection
7(clicking an item toggles the item on or off independently of other
8selections).
9
27d029c7
RR
10List box elements are numbered from zero. Their number is limited in
11some platforms (e.g. ca. 2000 on GTK).
a660d684 12
80b1853f 13A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECTED for single clicks, and
debe6624 14wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
a660d684
KB
15
16\wxheading{Derived from}
17
bed5584e 18\helpref{wxControlWithItems}{wxcontrolwithitems}\\
a660d684
KB
19\helpref{wxControl}{wxcontrol}\\
20\helpref{wxWindow}{wxwindow}\\
21\helpref{wxEvtHandler}{wxevthandler}\\
22\helpref{wxObject}{wxobject}
23
954b8ae6
JS
24\wxheading{Include files}
25
26<wx/listbox.h>
27
a660d684
KB
28\wxheading{Window styles}
29
30\twocolwidtha{5cm}%
31\begin{twocollist}\itemsep=0pt
32\twocolitem{\windowstyle{wxLB\_SINGLE}}{Single-selection list.}
33\twocolitem{\windowstyle{wxLB\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
34items on and off.}
35\twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
36select multiple items using the SHIFT key and the mouse or special key combinations.}
37\twocolitem{\windowstyle{wxLB\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).}
38\twocolitem{\windowstyle{wxLB\_ALWAYS\_SB}}{Always show a vertical scrollbar.}
39\twocolitem{\windowstyle{wxLB\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.}
3377b962 40\twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
a660d684
KB
41\end{twocollist}
42
54081dc5
VZ
43Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED}
44styles are mutually exclusive and you can specify at most one of them (single
45selection is the default).
46
a660d684
KB
47See also \helpref{window styles overview}{windowstyles}.
48
5de76427
JS
49\wxheading{Event handling}
50
51\twocolwidtha{7cm}
52\begin{twocollist}\itemsep=0pt
53\twocolitem{{\bf EVT\_LISTBOX(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_SELECTED event,
54when an item on the list is selected.}
def172b2 55\twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
2edb0bde 56when the listbox is double-clicked.}
5de76427
JS
57\end{twocollist}
58
a660d684
KB
59\wxheading{See also}
60
5de76427
JS
61\helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
62\rtfsp\helpref{wxCommandEvent}{wxcommandevent}
a660d684
KB
63
64\latexignore{\rtfignore{\wxheading{Members}}}
65
f0e8a2d0 66\membersection{wxListBox::wxListBox}\label{wxlistboxctor}
a660d684
KB
67
68\func{}{wxListBox}{\void}
69
70Default constructor.
71
eaaa6a06 72\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 73\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
1219d8a4 74\param{int}{ n = 0}, \param{const wxString }{choices[] = NULL},\rtfsp
eaaa6a06 75\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
a660d684 76
56b88f12
MB
77\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
78\param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
79\param{const wxArrayString\& }{choices},\rtfsp
80\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
81
a660d684
KB
82Constructor, creating and showing a list box.
83
84\wxheading{Parameters}
85
86\docparam{parent}{Parent window. Must not be NULL.}
87
88\docparam{id}{Window identifier. A value of -1 indicates a default value.}
89
90\docparam{pos}{Window position.}
91
92\docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
93appropriately.}
94
95\docparam{n}{Number of strings with which to initialise the control.}
96
97\docparam{choices}{An array of strings with which to initialise the control.}
98
99\docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
100
101\docparam{validator}{Window validator.}
102
103\docparam{name}{Window name.}
104
105\wxheading{See also}
106
107\helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
108
c9110876
VS
109\pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
110and {\tt choices} arguments are to a single argument, which is
06d20283
RD
111a list of strings.}
112
5873607e
VZ
113\perlnote{In wxPerl there is just an array reference in place of {\tt n}
114and {\tt choices}.}
06d20283 115
f0e8a2d0 116\membersection{wxListBox::\destruct{wxListBox}}\label{wxlistboxdtor}
a660d684
KB
117
118\func{void}{\destruct{wxListBox}}{\void}
119
120Destructor, destroying the list box.
121
a660d684
KB
122\membersection{wxListBox::Create}\label{wxlistboxcreate}
123
eaaa6a06 124\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 125\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
126\param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
127\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
a660d684 128
56b88f12
MB
129\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
130\param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
131\param{const wxArrayString\& }{choices},\rtfsp
132\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
133
f0e8a2d0 134Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxctor}\rtfsp
a660d684
KB
135for further details.
136
a660d684
KB
137\membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
138
139\func{void}{Deselect}{\param{int}{ n}}
140
141Deselects an item in the list box.
142
143\wxheading{Parameters}
144
145\docparam{n}{The zero-based item to deselect.}
146
147\wxheading{Remarks}
148
149This applies to multiple selection listboxes only.
150
a660d684
KB
151\membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
152
605d715d 153\constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
a660d684 154
fd9811b1 155Fill an array of ints with the positions of the currently selected items.
a660d684
KB
156
157\wxheading{Parameters}
158
fd9811b1 159\docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
a660d684
KB
160
161\wxheading{Return value}
162
163The number of selections.
164
165\wxheading{Remarks}
166
167Use this with a multiple selection listbox.
168
169\wxheading{See also}
170
bed5584e
VZ
171\helpref{wxControlWithItems::GetSelection}{wxcontrolwithitemsgetselection},\rtfsp
172\helpref{wxControlWithItems::GetStringSelection}{wxcontrolwithitemsgetstringselection},\rtfsp
173\helpref{wxControlWithItems::SetSelection}{wxcontrolwithitemssetselection}
a660d684 174
f899db6d
RD
175\pythonnote{The wxPython version of this method takes no parameters
176and returns a tuple of the selected items.}
177
2edb0bde 178\perlnote{In wxPerl this method takes no parameters and return the
5873607e
VZ
179selected items as a list.}
180
81108288
VZ
181\membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
182
1a090517 183\func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ *items}, \param{unsigned int}{ pos}}
81108288 184
1a090517 185\func{void}{InsertItems}{\param{const wxArrayString\&}{ nItems}, \param{unsigned int}{ pos}}
3980000c 186
81108288
VZ
187Insert the given number of strings before the specified position.
188
189\wxheading{Parameters}
190
191\docparam{nItems}{Number of items in the array {\it items}}
192
193\docparam{items}{Labels of items to be inserted}
194
195\docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items
196will be inserted in the beginning of the listbox}
197
76e1c2de
RD
198\pythonnote{The first two parameters are collapsed into a single
199parameter for wxPython, which is a list of strings.}
200
5873607e
VZ
201\perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
202and {\tt items}.}
203
c00fed0e
VZ
204\membersection{wxListBox::HitTest}\label{wxlistboxhittest}
205
206\constfunc{int}{HitTest}{\param{const wxPoint&}{ point}}
207
208Returns the item located at \arg{point}, or \texttt{wxNOT\_FOUND} if there
209is no item located at \arg{point}.
210
211\newsince{2.7.0}. It is currently implemented for wxMSW, wxMac and wxGTK2
212ports.
213
214\wxheading{Parameters}
215
216\docparam{point}{Point of item (in client coordinates) to obtain}
217
218\wxheading{Return value}
219
220Item located at \arg{point}, or \texttt{wxNOT\_FOUND} if unimplemented
221or the item does not exist.
222
4fb6c97e 223\membersection{wxListBox::IsSelected}\label{wxlistboxisselected}
a660d684 224
4fb6c97e 225\constfunc{bool}{IsSelected}{\param{int}{ n}}
a660d684
KB
226
227Determines whether an item is selected.
228
229\wxheading{Parameters}
230
231\docparam{n}{The zero-based item index.}
232
233\wxheading{Return value}
234
cc81d32f 235true if the given item is selected, false otherwise.
a660d684
KB
236
237\membersection{wxListBox::Set}\label{wxlistboxset}
238
2b5f62a0 239\func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
a660d684 240
2b5f62a0
VZ
241\func{void}{Set}{\param{const wxArrayString\&}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
242
243Clears the list box and adds the given strings to it.
a660d684
KB
244
245\wxheading{Parameters}
246
247\docparam{n}{The number of strings to set.}
248
249\docparam{choices}{An array of strings to set.}
250
2b5f62a0
VZ
251\docparam{clientData}{Options array of client data pointers}
252
a660d684
KB
253\wxheading{Remarks}
254
2b5f62a0
VZ
255You may free the array from the calling program after this function has been
256called.
a660d684 257
a660d684
KB
258\membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
259
260\func{void}{SetFirstItem}{\param{int}{ n}}
261
262\func{void}{SetFirstItem}{\param{const wxString\& }{string}}
263
953704c1 264Set the specified item to be the first visible item. Windows only.
a660d684
KB
265
266\wxheading{Parameters}
267
268\docparam{n}{The zero-based item index.}
269
270\docparam{string}{The string that should be visible.}
271