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 is limited in
11 some platforms (e.g. ca.
2000 on GTK).
13 A listbox callback gets an event wxEVT
\_COMMAND\_LISTBOX\_SELECT 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
}
28 \wxheading{Window styles
}
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
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.
}
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).
47 See also
\helpref{window styles overview
}{windowstyles
}.
49 \wxheading{Event handling
}
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.
}
61 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
},
62 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
64 \latexignore{\rtfignore{\wxheading{Members
}}}
66 \membersection{wxListBox::wxListBox
}\label{wxlistboxctor
}
68 \func{}{wxListBox
}{\void}
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"
}}
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"
}}
82 Constructor, creating and showing a list box.
84 \wxheading{Parameters
}
86 \docparam{parent
}{Parent window. Must not be NULL.
}
88 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
90 \docparam{pos
}{Window position.
}
92 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
95 \docparam{n
}{Number of strings with which to initialise the control.
}
97 \docparam{choices
}{An array of strings with which to initialise the control.
}
99 \docparam{style
}{Window style. See
\helpref{wxListBox
}{wxlistbox
}.
}
101 \docparam{validator
}{Window validator.
}
103 \docparam{name
}{Window name.
}
107 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
109 \pythonnote{The wxListBox constructor in wxPython reduces the
{\tt n
}
110 and
{\tt choices
} arguments are to a single argument, which is
113 \perlnote{In wxPerl there is just an array reference in place of
{\tt n
}
116 \membersection{wxListBox::
\destruct{wxListBox
}}\label{wxlistboxdtor
}
118 \func{void
}{\destruct{wxListBox
}}{\void}
120 Destructor, destroying the list box.
122 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
124 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
125 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
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"
}}
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"
}}
134 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxctor
}\rtfsp
137 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
139 \func{void
}{Deselect
}{\param{int
}{ n
}}
141 Deselects an item in the list box.
143 \wxheading{Parameters
}
145 \docparam{n
}{The zero-based item to deselect.
}
149 This applies to multiple selection listboxes only.
151 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
153 \constfunc{int
}{GetSelections
}{\param{wxArrayInt\&
}{selections
}}
155 Fill an array of ints with the positions of the currently selected items.
157 \wxheading{Parameters
}
159 \docparam{selections
}{A reference to an wxArrayInt instance that is used to store the result of the query.
}
161 \wxheading{Return value
}
163 The number of selections.
167 Use this with a multiple selection listbox.
171 \helpref{wxControlWithItems::GetSelection
}{wxcontrolwithitemsgetselection
},
\rtfsp
172 \helpref{wxControlWithItems::GetStringSelection
}{wxcontrolwithitemsgetstringselection
},
\rtfsp
173 \helpref{wxControlWithItems::SetSelection
}{wxcontrolwithitemssetselection
}
175 \pythonnote{The wxPython version of this method takes no parameters
176 and returns a tuple of the selected items.
}
178 \perlnote{In wxPerl this method takes no parameters and return the
179 selected items as a list.
}
181 \membersection{wxListBox::InsertItems
}\label{wxlistboxinsertitems
}
183 \func{void
}{InsertItems
}{\param{int
}{ nItems
},
\param{const wxString
}{ *items
},
\param{int
}{ pos
}}
185 \func{void
}{InsertItems
}{\param{const wxArrayString\&
}{ nItems
},
\param{int
}{ pos
}}
187 Insert the given number of strings before the specified position.
189 \wxheading{Parameters
}
191 \docparam{nItems
}{Number of items in the array
{\it items
}}
193 \docparam{items
}{Labels of items to be inserted
}
195 \docparam{pos
}{Position before which to insert the items: for example, if
{\it pos
} is
0 the items
196 will be inserted in the beginning of the listbox
}
198 \pythonnote{The first two parameters are collapsed into a single
199 parameter for wxPython, which is a list of strings.
}
201 \perlnote{In wxPerl there is just an array reference in place of
{\tt nItems
}
204 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
206 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
208 Determines whether an item is selected.
210 \wxheading{Parameters
}
212 \docparam{n
}{The zero-based item index.
}
214 \wxheading{Return value
}
216 true if the given item is selected, false otherwise.
218 \membersection{wxListBox::Set
}\label{wxlistboxset
}
220 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
},
\param{void
}{ **clientData =
{\tt NULL
}}}
222 \func{void
}{Set
}{\param{const wxArrayString\&
}{ choices
},
\param{void
}{ **clientData =
{\tt NULL
}}}
224 Clears the list box and adds the given strings to it.
226 \wxheading{Parameters
}
228 \docparam{n
}{The number of strings to set.
}
230 \docparam{choices
}{An array of strings to set.
}
232 \docparam{clientData
}{Options array of client data pointers
}
236 You may free the array from the calling program after this function has been
239 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
241 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
243 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
245 Set the specified item to be the first visible item. Windows only.
247 \wxheading{Parameters
}
249 \docparam{n
}{The zero-based item index.
}
251 \docparam{string
}{The string that should be visible.
}