1 \section{\class{wxListBox
}}\label{wxlistbox
}
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
10 List box elements are numbered from zero. Their number may be limited
13 A listbox callback gets an event wxEVT
\_COMMAND\_LISTBOX\_SELECTED for single clicks, and
14 wxEVT
\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
16 \wxheading{Derived from
}
18 \helpref{wxControlWithItems
}{wxcontrolwithitems
}\\
19 \helpref{wxControl
}{wxcontrol
}\\
20 \helpref{wxWindow
}{wxwindow
}\\
21 \helpref{wxEvtHandler
}{wxevthandler
}\\
22 \helpref{wxObject
}{wxobject
}
24 \wxheading{Include files
}
30 \helpref{wxCore
}{librarieslist
}
32 \wxheading{Window styles
}
35 \begin{twocollist
}\itemsep=
0pt
36 \twocolitem{\windowstyle{wxLB
\_SINGLE}}{Single-selection list.
}
37 \twocolitem{\windowstyle{wxLB
\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
39 \twocolitem{\windowstyle{wxLB
\_EXTENDED}}{Extended-selection list: the user can
40 select multiple items using the SHIFT key and the mouse or special key combinations.
}
41 \twocolitem{\windowstyle{wxLB
\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).
}
42 \twocolitem{\windowstyle{wxLB
\_ALWAYS\_SB}}{Always show a vertical scrollbar.
}
43 \twocolitem{\windowstyle{wxLB
\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.
}
44 \twocolitem{\windowstyle{wxLB
\_SORT}}{The listbox contents are sorted in alphabetical order.
}
47 Note that
{\tt wxLB
\_SINGLE},
{\tt wxLB
\_MULTIPLE} and
{\tt wxLB
\_EXTENDED}
48 styles are mutually exclusive and you can specify at most one of them (single
49 selection is the default).
51 See also
\helpref{window styles overview
}{windowstyles
}.
53 \wxheading{Event handling
}
56 \begin{twocollist
}\itemsep=
0pt
57 \twocolitem{{\bf EVT
\_LISTBOX(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_SELECTED event,
58 when an item on the list is selected or the selection changes.
}
59 \twocolitem{{\bf EVT
\_LISTBOX\_DCLICK(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
60 when the listbox is double-clicked.
}
65 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
},
66 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
68 \latexignore{\rtfignore{\wxheading{Members
}}}
70 \membersection{wxListBox::wxListBox
}\label{wxlistboxctor
}
72 \func{}{wxListBox
}{\void}
76 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
77 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
78 \param{int
}{ n =
0},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
79 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
81 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
82 \param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
83 \param{const wxArrayString\&
}{choices
},
\rtfsp
84 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
86 Constructor, creating and showing a list box.
88 \wxheading{Parameters
}
90 \docparam{parent
}{Parent window. Must not be NULL.
}
92 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
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{wxListBox
}{wxlistbox
}.
}
105 \docparam{validator
}{Window validator.
}
107 \docparam{name
}{Window name.
}
111 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
113 \pythonnote{The wxListBox 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
}
120 \membersection{wxListBox::
\destruct{wxListBox
}}\label{wxlistboxdtor
}
122 \func{void
}{\destruct{wxListBox
}}{\void}
124 Destructor, destroying the list box.
126 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
128 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
129 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
130 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
131 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
133 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
134 \param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
135 \param{const wxArrayString\&
}{choices
},
\rtfsp
136 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
138 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxctor
}\rtfsp
141 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
143 \func{void
}{Deselect
}{\param{int
}{ n
}}
145 Deselects an item in the list box.
147 \wxheading{Parameters
}
149 \docparam{n
}{The zero-based item to deselect.
}
153 This applies to multiple selection listboxes only.
155 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
157 \constfunc{int
}{GetSelections
}{\param{wxArrayInt\&
}{selections
}}
159 Fill an array of ints with the positions of the currently selected items.
161 \wxheading{Parameters
}
163 \docparam{selections
}{A reference to an wxArrayInt instance that is used to store the result of the query.
}
165 \wxheading{Return value
}
167 The number of selections.
171 Use this with a multiple selection listbox.
175 \helpref{wxControlWithItems::GetSelection
}{wxcontrolwithitemsgetselection
},
\rtfsp
176 \helpref{wxControlWithItems::GetStringSelection
}{wxcontrolwithitemsgetstringselection
},
\rtfsp
177 \helpref{wxControlWithItems::SetSelection
}{wxcontrolwithitemssetselection
}
179 \pythonnote{The wxPython version of this method takes no parameters
180 and returns a tuple of the selected items.
}
182 \perlnote{In wxPerl this method takes no parameters and return the
183 selected items as a list.
}
185 \membersection{wxListBox::InsertItems
}\label{wxlistboxinsertitems
}
187 \func{void
}{InsertItems
}{\param{int
}{ nItems
},
\param{const wxString
}{ *items
},
\param{unsigned int
}{ pos
}}
189 \func{void
}{InsertItems
}{\param{const wxArrayString\&
}{ nItems
},
\param{unsigned int
}{ pos
}}
191 Insert the given number of strings before the specified position.
193 \wxheading{Parameters
}
195 \docparam{nItems
}{Number of items in the array
{\it items
}}
197 \docparam{items
}{Labels of items to be inserted
}
199 \docparam{pos
}{Position before which to insert the items: for example, if
{\it pos
} is
0 the items
200 will be inserted in the beginning of the listbox
}
202 \pythonnote{The first two parameters are collapsed into a single
203 parameter for wxPython, which is a list of strings.
}
205 \perlnote{In wxPerl there is just an array reference in place of
{\tt nItems
}
208 \membersection{wxListBox::HitTest
}\label{wxlistboxhittest
}
210 \constfunc{int
}{HitTest
}{\param{const wxPoint&
}{ point
}}
212 Returns the item located at
\arg{point
}, or
\texttt{wxNOT
\_FOUND} if there
213 is no item located at
\arg{point
}.
215 \newsince{2.7.0}. It is currently implemented for wxMSW, wxMac and wxGTK2
218 \wxheading{Parameters
}
220 \docparam{point
}{Point of item (in client coordinates) to obtain
}
222 \wxheading{Return value
}
224 Item located at
\arg{point
}, or
\texttt{wxNOT
\_FOUND} if unimplemented
225 or the item does not exist.
227 \membersection{wxListBox::IsSelected
}\label{wxlistboxisselected
}
229 \constfunc{bool
}{IsSelected
}{\param{int
}{ n
}}
231 Determines whether an item is selected.
233 \wxheading{Parameters
}
235 \docparam{n
}{The zero-based item index.
}
237 \wxheading{Return value
}
239 true if the given item is selected, false otherwise.
241 \membersection{wxListBox::Set
}\label{wxlistboxset
}
243 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
},
\param{void
}{ **clientData =
{\tt NULL
}}}
245 \func{void
}{Set
}{\param{const wxArrayString\&
}{ choices
},
\param{void
}{ **clientData =
{\tt NULL
}}}
247 Clears the list box and adds the given strings to it.
249 \wxheading{Parameters
}
251 \docparam{n
}{The number of strings to set.
}
253 \docparam{choices
}{An array of strings to set.
}
255 \docparam{clientData
}{Options array of client data pointers
}
259 You may free the array from the calling program after this function has been
262 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
264 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
266 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
268 Set the specified item to be the first visible item.
270 \wxheading{Parameters
}
272 \docparam{n
}{The zero-based item index.
}
274 \docparam{string
}{The string that should be visible.
}