List Box Component
insert a list box in a worksheet or document
Description
Component Palette Image
List Box Properties
List Box Example
The list box component performs an action or a series of actions to communicate with other embedded components when an item from the list box is selected, although assigning an action to a component is not required.
To perform an action when an item from a list box is selected, click the list box, and then, from the context panel, select Edit Select Code. Enter the commands you want to perform in the Code Editor dialog.
You need to specify one or more embedded components that will display the output when an item from the list box is selected. For more information, see the List Box Component Example on this page.
The list box component is customized by setting options in the List Box context panel. To view the List Box context panel, select the list box. Actions are associated with components using routines in the DocumentTools package.
The Name property is used to reference the list box when using the routines from the DocumentTools package.
To populate the list box with entries, select the Edit button beside Item List. In the List Editor that displays, add the first item by double-clicking the text field and edit this region. To add additional items, click the Add button to display an additional text field and proceed to edit the entry as illustrated in the previous step. After you have populated the list box, select the drop-down menu beside Selected Item and choose the item that will be the default item highlighted in the list box.
The following table describes the control and use of the list box component options.
An x in the Get column indicates that the option can be read, that is, retrieved by using the DocumentTools[GetProperty] tool.
An x in the Set column indicates that the option can be written, that is, set by using the DocumentTools[SetProperty] tool.
Option
Get
Set
Option Type
enabled
x
true or false
fillcolor
color
fontcolor
itemList
list or set
selectmultiple
selectedindices
list of non-negative integers
selectedindex
non-negative integer
selecteditemlist
tooltip
string
type
value
visible
visiblerows
Whether the component is enabled. If enabled is set to false, the component is grayed out and any action associated with it cannot be initiated. By default, the value is true.
Specifies the background color of the component. The color can be given by RGB values (a list of three integers between 0 and 255) or a string representing a color name, for example, [255,0,0] or “Red”. The default value is [255,255,255] which corresponds to white.
Specifies the font color of the component. The default value is [0,0,0] which corresponds to black.
The set of items provided in the List Box.
Indicates whether selecting multiple items is permitted. By default, the value is false.
The set of all indices for items which are selected. The first index is 0.
The index of the item which is selected. When multiple items are selected, it is the first index of selectedindices. The first index is 0.
The set of all items which are selected.
The text that appears when the user hovers the mouse over the list box.
The type of the component. This returns "ListBox".
The selected item, or if multiple items are selected, the first selected item.
Specifies if the list box is visible. By default, the value is true.
Specifies the number of rows of the list box that are displayed. (A scroll bar is added if the size of the item list is greater than visiblerows. By default, the list box size is determined by the number of items in the item list.
Note: To interact with the example provided below, open this help page as a worksheet and then execute the worksheet.
This example displays a list of colors in a List Box component. When you click on a color in the list box, the color of curve in the Plot component changes.
To insert the components and add the colors to the list box:
Insert a List Box and a Plot component using the Components palette. For information on displaying the Maple palettes, see the Show Palettes help page.
Click the list box component to open the context panel.
Click the Edit button of the Item List field.
Double-click the first row and replace ListBox with blue.
Click Add, double-click the new field, and then replace the default entry with red.
Repeat step 5 and add the following items to the list: black, green, magenta, and yellow. When finished, click OK to close the List Editor.
To have a list box item selection change the color of the plot of sin(x):
Click the list box, and then select Edit Select Code.
This launches the Code Editor dialog.
Before the end use; statement in the dialog, enter the following command:
SetProperty("Plot0", value, plot(sin(x), x = 0..10, color = GetProperty("ListBox0", value)));
Note: Ensure the names of the components are correct (that is, that they match the Name fields for their components).
Click or from the File menu, select Save Code to accept all changes.
From the File menu, select Close Code Editor.
When you select an item from the list box, the color of the plot changes to the selection.
blueredblackgreenmagentayellow
with(DocumentTools):
You can verify the syntax of the embedded component action by executing the command in the worksheet.
See Also
DocumentTools
DocumentTools[GetProperty]
DocumentTools[SetProperty]
EmbeddedComponents
Maplets[Elements][ListBox]
PlotComponent
Download Help Document