Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

listdlg

Create list selection dialog box

Syntax

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

Description

[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, {'One','Two','Three'} creates 3 list items. Newline characters inserted using sprintf will result in more list items.

'SelectionMode'

Selection mode for allowing single or multiple selections. The possible values are 'single' and 'multiple', where 'multiple' is the default value.

'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'

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 'OK'.

'CancelString'

Label for the Cancel button. Default label 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

collapse all

Modal Dialog Box

A window that blocks interaction with other windows until the user closes it.

Introduced before R2006a

Was this topic helpful?