listdlg

Create and open list-selection dialog box

Syntax

[Selection,ok] = listdlg('ListString',S)

Description

[Selection,ok] = listdlg('ListString',S) creates a modal dialog that enables you to select one or more items from a list. Selection is a vector of indices of the selected strings (in single selection mode, its length is 1). Selection is [] when ok is 0. ok is 1 if you click the OK button, or 0 if you click the Cancel button or close the dialog box. 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.

Inputs are in parameter/value pairs:

Parameter

Description

'ListString'

Cell array of strings that specify the list box items.

'SelectionMode'

String indicating whether one or many items can be selected: 'single' or 'multiple' (the default).

'ListSize'

List box size in pixels, specified as a two-element vector [width height]. Default is [160 300].

'InitialValue'

Vector of indices of the list box items that are initially selected. Default is 1, the first item.

'Name'

String for the dialog box's title. Default is ''.

'PromptString'

String matrix or cell array of strings that appears as text above the list box. Default is {}.

'OKString'

String for the OK button. Default is 'OK'.

'CancelString'

String for the Cancel button. Default is 'Cancel'.

'uh'

Uicontrol button height, in pixels. Default is 18.

'fus'

Frame/uicontrol spacing, in pixels. Default is 8.

'ffs'

Frame/figure spacing, in pixels. Default is 8.

Examples

This example displays a dialog box that enables the user to select a file from the current directory. The function returns a vector. Its first element is the index to the selected file; its second element is 0 if no selection is made, or 1 if a selection is made.

d = dir;
str = {d.name};
[s,v] = listdlg('PromptString','Select a file:',...
                'SelectionMode','single',...
                'ListString',str)

More About

expand all

Modal Dialog

A window that prevents the user from interacting with other windows before responding. For more information, see the figure WindowStyle property description.

Was this topic helpful?