Back to Devexpress

ASPxClientListBox.GetSelectedItems Method

aspnet-js-aspxclientlistbox-0d570238.md

latest4.1 KB
Original Source

ASPxClientListBox.GetSelectedItems Method

Returns an array of the list editor’s selected items.

Declaration

ts
GetSelectedItems(): ASPxClientListEditItem[]

Returns

TypeDescription
ASPxClientListEditItem[]

An array of ASPxClientListEditItem objects that represent the selected items.

|

Remarks

Use the GetSelectedItems method to obtain an array of the selected items within a list box. A null value indicates that no item is currently selected within the list editor.

Note

The GetSelectedItems method is not in effect if the ASPxListBox.SelectionMode property is set to ListEditSelectionMode.Single value.

For more information about multiple selection, read the Multi-Selection Mode topic.

Example

The following section of the Moving Items Between Two List Boxes online demo illustrates how moving ASPxListBox items is implemented using the client ASPxClientListBox.GetSelectedItems, ASPxClientListBox.AddItem, ASPxClientListBox.RemoveItem, ASPxClientListBox.BeginUpdate and ASPxClientListBox.EndUpdate methods.

javascript
function AddSelectedItems() {
    MoveSelectedItems(lbAvailable, lbChoosen);
...
}

function RemoveSelectedItems() {
    MoveSelectedItems(lbChoosen, lbAvailable);
...
}
function MoveSelectedItems(srcListBox, dstListBox) {
    srcListBox.BeginUpdate();
    dstListBox.BeginUpdate();
    var items = srcListBox.GetSelectedItems();
    for(var i = items.length - 1; i >= 0; i = i - 1) {
        dstListBox.AddItem(items[i].text, items[i].value);
        srcListBox.RemoveItem(items[i].index);
    }
    srcListBox.EndUpdate();
    dstListBox.EndUpdate();
}
aspx
<!-- ASPxListBox controls -->

<dxe:ASPxListBox ID="lbAvailable" runat="server" ClientInstanceName="lbAvailable"
Width="230px" Height="240px" SelectionMode="CheckColumn">
    <Items>
        <dxe:ListEditItem Text="ASPxEditors Suite" Value="ASPxEditors" />
        <dxe:ListEditItem Text="ASPxGauges Suite" Value="ASPxGauges" />
        ...
    </Items>
...
</dxe:ASPxListBox>
...
<dxe:ASPxListBox ID="lbChoosen" runat="server" ClientInstanceName="lbChoosen"
Width="230px" Height="240px" SelectionMode="CheckColumn">
...
</dxe:ASPxListBox>

<!-- ASPxButtons -->

<dxe:ASPxButton ID="btnMoveSelectedItemsToRight" runat="server" 
ClientInstanceName="btnMoveSelectedItemsToRight" AutoPostBack="False" 
Text="Add >" Width="120px" Height="23px" ClientEnabled="False" 
ToolTip="Add selected items">
    <ClientSideEvents Click="function(s, e) { AddSelectedItems(); }" />
</dxe:ASPxButton>

<dxe:ASPxButton ID="btnMoveSelectedItemsToLeft" runat="server" 
ClientInstanceName="btnMoveSelectedItemsToLeft"
AutoPostBack="False" Text="< Remove" Width="120px" Height="23px" 
ClientEnabled="False" ToolTip="Remove selected items">
    <ClientSideEvents Click="function(s, e) { RemoveSelectedItems(); }" />
</dxe:ASPxButton>

See Also

SelectedItems

SelectionMode

SelectItems(items)

UnselectItems(items)

SelectAll

UnselectAll

Selected

List Box

ASPxClientListBox Class

ASPxClientListBox Members