Create list selection dialog box
[Selection,ok] = listdlg(Name,Value,...)
[Selection,ok] = listdlg(Name,Value,...)
creates
a modal dialog box that
allows the user to select one or more items from a list. The function
returns two output arguments containing information about the items
the user selected. The first output, Selection
,
contains the indices of the selected rows in the list. Selection
is
an empty array when no selection is made. The second output, ok
,
is 0 when no selection is made, or 1 when a selection is made.
The input arguments, Name,Value
, are pairs
of arguments that specify certain aspects of the dialog box. The pair, 'ListString',S
is
required, but you can optionally specify any number of other pairs.
This table lists all possible Name,Value
input
arguments:
Name | Value |
---|---|
'ListString' (required) | Cell array of character vectors that specify the list
items. Typically, each element in the cell array corresponds to an
item in the list. For example, |
'SelectionMode' | Selection mode for allowing single or multiple selections.
The possible values are |
'ListSize' | List box size in pixels, specified as a two-element vector |
'InitialValue' | Vector of indices of the list box items that are initially selected. Default is 1, the first item. |
'Name' | Dialog box title. The default value is an empty character vector. |
'PromptString' | Prompt that appears above the list box. Specify this prompt as a character vector or cell array of character vectors. |
'OKString' | Label for the OK button. The default
label is |
'CancelString' | Label for the Cancel button. Default
label is |
Double-clicking on an item or pressing Return when multiple items are selected has the same effect as clicking the OK button. The dialog box has a Select all button (when in multiple selection mode) that enables you to select all list items.
This example displays a dialog box that enables the user to select a file from the current directory.
The listdlg
function returns two output
arguments. The first output, s
, is the index to
the selected row in the list. The second output, v
,
is 0 when no selection is made, or 1 when a selection is made.
d = dir; str = {d.name}; [s,v] = listdlg('PromptString','Select a file:',... 'SelectionMode','single',... 'ListString',str)