Documentation

listdlg

Create list-selection dialog box

Syntax

[Selection,ok] = listdlg(Name,Value,...)

Description

[Selection,ok] = listdlg(Name,Value,...) creates a modal dialog 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 strings that specify the list 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 an empty string.

'PromptString'

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

'OKString'

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

'CancelString'

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

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.

Examples

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)

More About

expand all

Modal Dialog

A window that blocks interaction with other windows until the user closes the blocking window. For more information, see the figure WindowStyle property description.

Introduced before R2006a

Was this topic helpful?