Skip to content

MultiSelect

class cAlgo.API Since 5.6

DesktopCLICloud

A control that shows list of unique items and allows user to select multiple items from the list

Environment behaviour

CLI — not supported. Accepted without error but never displayed, so control events such as Click are never raised.

Cloud — not supported. Accepted without error but never displayed, so control events such as Click are never raised.

Definition

public class MultiSelect : Control

Namespace: cAlgo.API · Group: Controls · Inherits: Control, ControlBase

Examples

using cAlgo.API;

namespace cAlgo.Robots
{
    public partial class MultiSelectTest : Robot
    {
        private MultiSelect _multiSelect;

        protected override void OnStart()
        {
            _multiSelect = new MultiSelect();

            if (Styled)
            {
                _multiSelect.BackgroundColor = Color.Red;
                _multiSelect.FontWeight = FontWeight.UltraBold;
                _multiSelect.ForegroundColor = Color.Yellow;
                _multiSelect.FontSize = 40;
                _multiSelect.FontFamily = "Comic Sans MS";
            }

            for (var i = 0; i < 10; i++)
            {
                _multiSelect.AddItem($"Item {i}");
            }

            _multiSelect.SelectedItemsChanged += args => Print($"OnSelectedItemsChanged: {string.Join(", ", _multiSelect.SelectedItems)}");

            var addItemTextBox = new TextBox();

            var addItemButton = new Button() { Text = "Add Item" };

            addItemButton.Click += args =>
            {
                if (string.IsNullOrWhiteSpace(addItemTextBox.Text))
                    return;

                Print($"Add Result of {addItemTextBox.Text}: {_multiSelect.AddItem(addItemTextBox.Text)}");
            };

            var removeItemTextBox = new TextBox();

            var removeItemButton = new Button() { Text = "Remove Item" };

            removeItemButton.Click += args =>
            {
                if (string.IsNullOrWhiteSpace(removeItemTextBox.Text))
                    return;

                Print($"Remove Result of {removeItemTextBox.Text}: {_multiSelect.RemoveItem(removeItemTextBox.Text)}");
            };

            var selectItemTextBox = new TextBox();

            var selectItemButton = new Button() { Text = "Select Item" };

            selectItemButton.Click += args =>
            {
                if (string.IsNullOrWhiteSpace(selectItemTextBox.Text))
                    return;

                Print($"Select Result of {selectItemTextBox.Text}: {_multiSelect.SelectItem(selectItemTextBox.Text)}");
            };

            var unselectItemTextBox = new TextBox();

            var unselectItemButton = new Button() { Text = "Unselect Item" };

            unselectItemButton.Click += args =>
            {
                if (string.IsNullOrWhiteSpace(unselectItemTextBox.Text))
                    return;

                Print($"Unselect Result of {unselectItemTextBox.Text}: {_multiSelect.UnselectItem(unselectItemTextBox.Text)}");
            };

            var selectAllItemsButton = new Button() { Text = "Select All Items" };

            selectAllItemsButton.Click += args =>
            {
                _multiSelect.SelectAllItems();
            };

            var unselectAllItemsButton = new Button() { Text = "Unselect All Items" };

            unselectAllItemsButton.Click += args =>
            {
                _multiSelect.UnselectAllItems();
            };

            var showItemsButton = new Button() { Text = "Show Items" };

            showItemsButton.Click += args => Print($"Items: {string.Join(", ", _multiSelect.Items)}");

            var showSelectedItemsButton = new Button() { Text = "Show Selected Items" };

            showSelectedItemsButton.Click += args => Print($"Selected Items: {string.Join(", ", _multiSelect.SelectedItems)}");

            var panel = new StackPanel() { Orientation = Orientation.Vertical, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };

            panel.AddChild(_multiSelect);
            panel.AddChild(addItemTextBox);
            panel.AddChild(addItemButton);
            panel.AddChild(removeItemTextBox);
            panel.AddChild(removeItemButton);
            panel.AddChild(selectItemTextBox);
            panel.AddChild(selectItemButton);
            panel.AddChild(unselectItemTextBox);
            panel.AddChild(unselectItemButton);
            panel.AddChild(selectAllItemsButton);
            panel.AddChild(unselectAllItemsButton);
            panel.AddChild(showItemsButton);
            panel.AddChild(showSelectedItemsButton);

            Chart.AddControl(panel);
        }
    }
}
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *
# Import trading wrapper functions
from robot_wrapper import *

class Test():
    def on_add_item_button_clicked(self, args):
        if self.addItemTextBox.Text is None:
            return

        api.Print(f"Add Result of {self.addItemTextBox.Text}: {self.multiSelect.AddItem(self.addItemTextBox.Text)}")

    def on_remove_item_button_clicked(self, args):
        if self.removeItemTextBox.Text is None:
            return

        api.Print(f"Remove Result of {self.removeItemTextBox.Text}: {self.multiSelect.RemoveItem(self.removeItemTextBox.Text)}")

    def on_select_item_button_clicked(self, args):
        if self.selectItemTextBox.Text is None:
            return

        api.Print(f"Select Result of {self.selectItemTextBox.Text}: {self.multiSelect.SelectItem(self.selectItemTextBox.Text)}")

    def on_unselect_item_button_clicked(self, args):
        if self.unselectItemTextBox.Text is None:
            return

        api.Print(f"Unselect Result of {self.unselectItemTextBox.Text}: {self.multiSelect.UnselectItem(self.unselectItemTextBox.Text)}")

    def on_start(self):
        self.multiSelect = MultiSelect()

        if api.Styled:
            self.multiSelect.BackgroundColor = Color.Red
            self.multiSelect.FontWeight = FontWeight.UltraBold
            self.multiSelect.ForegroundColor = Color.Yellow
            self.multiSelect.FontSize = 40
            self.multiSelect.FontFamily = "Comic Sans MS"

        for i in range(10):
            self.multiSelect.AddItem(f"Item {i}")

        self.multiSelect.SelectedItemsChanged += lambda args: api.Print(f"OnSelectedItemsChanged: {', '.join(self.multiSelect.SelectedItems)}")

        self.addItemTextBox = TextBox()

        addItemButton = Button()
        addItemButton.Text = "Add Item"
        addItemButton.Click += self.on_add_item_button_clicked

        self.removeItemTextBox = TextBox()

        removeItemButton = Button()
        removeItemButton.Text = "Remove Item"
        removeItemButton.Click += self.on_remove_item_button_clicked

        self.selectItemTextBox = TextBox()

        selectItemButton = Button()
        selectItemButton.Text = "Select Item"
        selectItemButton.Click += self.on_select_item_button_clicked

        self.unselectItemTextBox = TextBox()

        unselectItemButton = Button()
        unselectItemButton.Text = "Unselect Item"
        unselectItemButton.Click += self.on_unselect_item_button_clicked

        selectAllItemsButton = Button()
        selectAllItemsButton.Text = "Select All Items"
        selectAllItemsButton.Click += lambda _: self.multiSelect.SelectAllItems()

        unselectAllItemsButton = Button()
        unselectAllItemsButton.Text = "Unselect All Items"
        unselectAllItemsButton.Click += lambda _: self.multiSelect.UnselectAllItems()

        showItemsButton = Button()
        showItemsButton.Text = "Show Items"
        showItemsButton.Click += lambda _: api.Print(f"Items: {', '.join(self.multiSelect.Items)}")

        showSelectedItemsButton = Button()
        showSelectedItemsButton.Text = "Show Selected Items"
        showSelectedItemsButton.Click += lambda _: api.Print(f"Selected Items: {', '.join(self.multiSelect.SelectedItems)}")

        panel = StackPanel()
        panel.Orientation = Orientation.Vertical
        panel.HorizontalAlignment = HorizontalAlignment.Center
        panel.VerticalAlignment = VerticalAlignment.Center

        panel.AddChild(self.multiSelect)
        panel.AddChild(self.addItemTextBox)
        panel.AddChild(addItemButton)
        panel.AddChild(self.removeItemTextBox)
        panel.AddChild(removeItemButton)
        panel.AddChild(self.selectItemTextBox)
        panel.AddChild(selectItemButton)
        panel.AddChild(self.unselectItemTextBox)
        panel.AddChild(unselectItemButton)
        panel.AddChild(selectAllItemsButton)
        panel.AddChild(unselectAllItemsButton)
        panel.AddChild(showItemsButton)
        panel.AddChild(showSelectedItemsButton)

        api.Chart.AddControl(panel)
{
  "AccessRights": "None",
  "AddIndicators": true,
  "Parameters": [
    {
      "Name": "Styled",
      "Type": "Boolean",
      "DefaultValue": false
    }
  ]
}

Constructors

Name Description
MultiSelectDesktopCLICloud Creates a new empty MultiSelect with default MultiSelect Style

Methods

Name Description
AddItemDesktopCLICloudbool Adds a new item to the MultiSelect
RemoveItemDesktopCLICloudbool Removes an existing item from the MultiSelect
SelectAllItemsDesktopCLICloudvoid Selects all items on the MultiSelect
SelectItemDesktopCLICloudbool Selects item on the MultiSelect
SelectItemsDesktopCLICloudvoid Selects items on the MultiSelect
UnselectAllItemsDesktopCLICloudvoid Unselects all items on the MultiSelect
UnselectItemDesktopCLICloudbool Unselects item on the MultiSelect
UnselectItemsDesktopCLICloudvoid Unselects items on the MultiSelect

Properties

Name Description
ItemsDesktopCLICloudIReadonlyList<string> Get the read-only copy of MultiSelect items
SelectedItemsDesktopCLICloudIReadonlyList<string> Get the read-only copy of MultiSelect selected items

Events

Name Description
SelectedItemsChangedDesktopCLICloudAction<MultiSelectSelectedItemsChangedEventArgs> This event will trigger if the MultiSelect selected items changed

Inherited members

From Control: ForegroundColor, BackgroundColor, Padding, VerticalContentAlignment, HorizontalContentAlignment, FontWeight, FontStyle, FontFamily, FontSize

From ControlBase: ResetProperty, UniqueId, Style, Left, Top, Right, Bottom, Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight, IsEnabled, IsVisible, Opacity, Margin, VerticalAlignment, HorizontalAlignment, Dock, IsHitTestVisible