Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

listdlg

Create list selection dialog box

Syntax

[indx,tf] = listdlg('ListString',list)
[indx,tf] = listdlg('ListString',list,Name,Value)

Description

example

[indx,tf] = listdlg('ListString',list) creates a modal dialog box that allows the user to select one or more items from the specified list.

The list value is the list of items to present in the dialog box.

The function returns two output arguments, indx and tf containing information about which items the user selected.

The dialog box includes Select all, Cancel, and OK buttons. You can limit selection to a single item by using the name-value pair, 'SelectionMode','single'.

Note

A modal dialog box prevents the user from interacting with other windows before responding. For more information, see WindowStyle in the MATLAB® Figure Properties.

example

[indx,tf] = listdlg('ListString',list,Name,Value) specifies additional options using one or more name-value pair arguments. For example, 'PromptString','Select a Color' presents Select a Color above the list.

Examples

collapse all

list = {'Red','Yellow','Blue',...                   
'Green','Orange','Purple'};
[indx,tf] = listdlg('ListString',list);

d = dir;
fn = {d.name};
[indx,tf] = listdlg('PromptString','Select a file:',...
                           'SelectionMode','single',...
                           'ListString',fn);

Input Arguments

collapse all

List of items to present in the dialog box, specified as a character vector, cell array of character vectors, or string array. For cell arrays and string arrays, each element typically corresponds to a separate list item. If you insert newline characters using sprintf, it results in more list items. For example, the following code results in four list items, even though there are only three cell array elements.

f = listdlg('ListString', ...
            {'John Smith' ...
             sprintf('Cecelia\nPayne-Gaposchkin') ...
             'Gina Peters'});

Example: {'Ellen','Varun','Haruko','Roger'}

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'SelectionMode,'single','InitialValue',4 specifies that the user can select one item from the list and that when the dialog box opens, the fourth item in the list is selected.

collapse all

List box prompt, specified as a character vector, cell array of character vectors, or string array. The prompt appears above the list box.

  • If you specify the prompt as a character vector, then a long vector wraps to fit the dialog box.

  • If you specify the prompt as a cell array or string array, then line breaks occur between each array element. Long elements wrap to fit the dialog box

Example: 'PromptString','Select a catalog number:'

List selection mode specified as the comma-separated pair consisting of 'SelectionMode' and either 'multiple' or 'single'.

  • If the selection mode is set to 'multiple', then users can select multiple list items and the Select all button displays in the dialog box.

  • If the selection mode is set to 'single', then users can select one list item only and the Select all button does not display in the dialog box.

Example: 'SelectionMode','single'

List box size in pixels, specified as the comma-separated pair consisting of 'ListSize' and a two-element vector, [width height].

Example: 'ListSize',[150,250]

Selected list box items, specified as a scalar index value when 'SelectionMode' is set to 'single' and specified as a vector of indices when 'SelectionMode' is set to 'multiple'. The indices indicate which rows in the list box are selected when the dialog box opens. For example:

  • If 'InitialValue' is set to 3, then the third item from the top of the list is selected when the dialog box opens.

  • If 'InitialValue' is set to [3 4], then the third and fourth items from the top of the list are selected when the dialog box opens.

Example: 'InitialValue',5

Example: 'InitialValue',[2 5]

Dialog box title, specified as a character vector or string scalar.

Example: 'Name','File Selection'

OK button label, specified as a character vector or string scalar.

Example: 'OKString','Apply'

Cancel button label, specified as a character vector or string scalar.

Example: 'CancelString','No Selection'

Output Arguments

collapse all

Index to selected rows, returned as an array of indices. The row indices correspond to selections the user made from the list. If the user clicks Cancel, presses Esc, or clicks the close button in the dialog box title bar, then the indx value is returned as an empty array.

Selection logical returned as 1 or 0.

The selection logical value indicates whether the user made a selection. If the user clicks OK, double-clicks a list item, or presses Return, then the tf return value is 1.

If the user clicks Cancel, presses Esc, or clicks the close button (X) in the dialog box title bar, then the tf return value is 0.

More About

collapse all

Modal Dialog Box

A modal dialog box prevents the user from interacting with other MATLAB windows before responding.

See Also

|

Introduced before R2006a

Was this topic helpful?