This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Create list selection dialog box


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


[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:



'ListString' (required)

Cell array of strings that specify the list items.


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


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


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


String for the dialog box's title. Default is an empty string.


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


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


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.


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 = {};
[s,v] = listdlg('PromptString','Select a file:',...

More About

collapse 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?