]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/listbox.tex
Improve wxHashMap documentation.
[wxWidgets.git] / docs / latex / wx / listbox.tex
1 \section{\class{wxListBox}}\label{wxlistbox}
2
3 A listbox is used to select one or more of a list of strings. The
4 strings are displayed in a scrolling box, with the selected string(s)
5 marked in reverse video. A listbox can be single selection (if an item
6 is selected, the previous selection is removed) or multiple selection
7 (clicking an item toggles the item on or off independently of other
8 selections).
9
10 List box elements are numbered from zero. Their number is limited in
11 some platforms (e.g. ca. 2000 on GTK).
12
13 A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECT for single clicks, and
14 wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
15
16 \wxheading{Derived from}
17
18 \helpref{wxControlWithItems}{wxcontrolwithitems}\\
19 \helpref{wxControl}{wxcontrol}\\
20 \helpref{wxWindow}{wxwindow}\\
21 \helpref{wxEvtHandler}{wxevthandler}\\
22 \helpref{wxObject}{wxobject}
23
24 \wxheading{Include files}
25
26 <wx/listbox.h>
27
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
34 items on and off.}
35 \twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
36 select 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.}
40 \twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
41 \end{twocollist}
42
43 Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED}
44 styles are mutually exclusive and you can specify at most one of them (single
45 selection is the default).
46
47 See also \helpref{window styles overview}{windowstyles}.
48
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,
54 when an item on the list is selected.}
55 \twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
56 when the listbox is double-clicked.}
57 \end{twocollist}
58
59 \wxheading{See also}
60
61 \helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
62 \rtfsp\helpref{wxCommandEvent}{wxcommandevent}
63
64 \latexignore{\rtfignore{\wxheading{Members}}}
65
66 \membersection{wxListBox::wxListBox}\label{wxlistboxconstr}
67
68 \func{}{wxListBox}{\void}
69
70 Default constructor.
71
72 \func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
73 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
74 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
75 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
76
77 Constructor, creating and showing a list box.
78
79 \wxheading{Parameters}
80
81 \docparam{parent}{Parent window. Must not be NULL.}
82
83 \docparam{id}{Window identifier. A value of -1 indicates a default value.}
84
85 \docparam{pos}{Window position.}
86
87 \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
88 appropriately.}
89
90 \docparam{n}{Number of strings with which to initialise the control.}
91
92 \docparam{choices}{An array of strings with which to initialise the control.}
93
94 \docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
95
96 \docparam{validator}{Window validator.}
97
98 \docparam{name}{Window name.}
99
100 \wxheading{See also}
101
102 \helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
103
104 \pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
105 and {\tt choices} arguments are to a single argument, which is
106 a list of strings.}
107
108 \perlnote{In wxPerl there is just an array reference in place of {\tt n}
109 and {\tt choices}.}
110
111 \membersection{wxListBox::\destruct{wxListBox}}
112
113 \func{void}{\destruct{wxListBox}}{\void}
114
115 Destructor, destroying the list box.
116
117 \membersection{wxListBox::Create}\label{wxlistboxcreate}
118
119 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
120 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
121 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
122 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
123
124 Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp
125 for further details.
126
127 \membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
128
129 \func{void}{Deselect}{\param{int}{ n}}
130
131 Deselects an item in the list box.
132
133 \wxheading{Parameters}
134
135 \docparam{n}{The zero-based item to deselect.}
136
137 \wxheading{Remarks}
138
139 This applies to multiple selection listboxes only.
140
141 \membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
142
143 \constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
144
145 Fill an array of ints with the positions of the currently selected items.
146
147 \wxheading{Parameters}
148
149 \docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
150
151 \wxheading{Return value}
152
153 The number of selections.
154
155 \wxheading{Remarks}
156
157 Use this with a multiple selection listbox.
158
159 \wxheading{See also}
160
161 \helpref{wxControlWithItems::GetSelection}{wxcontrolwithitemsgetselection},\rtfsp
162 \helpref{wxControlWithItems::GetStringSelection}{wxcontrolwithitemsgetstringselection},\rtfsp
163 \helpref{wxControlWithItems::SetSelection}{wxcontrolwithitemssetselection}
164
165 \pythonnote{The wxPython version of this method takes no parameters
166 and returns a tuple of the selected items.}
167
168 \perlnote{In wxPerl this method takes no parameters and return the
169 selected items as a list.}
170
171 \membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
172
173 \func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ *items}, \param{int}{ pos}}
174
175 Insert the given number of strings before the specified position.
176
177 \wxheading{Parameters}
178
179 \docparam{nItems}{Number of items in the array {\it items}}
180
181 \docparam{items}{Labels of items to be inserted}
182
183 \docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items
184 will be inserted in the beginning of the listbox}
185
186 \pythonnote{The first two parameters are collapsed into a single
187 parameter for wxPython, which is a list of strings.}
188
189 \perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
190 and {\tt items}.}
191
192 \membersection{wxListBox::Selected}\label{wxlistboxselected}
193
194 \constfunc{bool}{Selected}{\param{int}{ n}}
195
196 Determines whether an item is selected.
197
198 \wxheading{Parameters}
199
200 \docparam{n}{The zero-based item index.}
201
202 \wxheading{Return value}
203
204 true if the given item is selected, false otherwise.
205
206 \membersection{wxListBox::Set}\label{wxlistboxset}
207
208 \func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
209
210 \func{void}{Set}{\param{const wxArrayString\&}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
211
212 Clears the list box and adds the given strings to it.
213
214 \wxheading{Parameters}
215
216 \docparam{n}{The number of strings to set.}
217
218 \docparam{choices}{An array of strings to set.}
219
220 \docparam{clientData}{Options array of client data pointers}
221
222 \wxheading{Remarks}
223
224 You may free the array from the calling program after this function has been
225 called.
226
227 \membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
228
229 \func{void}{SetFirstItem}{\param{int}{ n}}
230
231 \func{void}{SetFirstItem}{\param{const wxString\& }{string}}
232
233 Set the specified item to be the first visible item. Windows only.
234
235 \wxheading{Parameters}
236
237 \docparam{n}{The zero-based item index.}
238
239 \docparam{string}{The string that should be visible.}
240