MultiSelect
Summary
A control that shows list of unique items and allows user to select multiple items from the list
Signature
| public class MultiSelect : Control
|
Namespace
cAlgo.API
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 | using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None, AddIndicators = true)]
public class MultiSelectTest : Robot
{
private MultiSelect _multiSelect;
[Parameter(DefaultValue = false)]
public bool Styled { get; set; }
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);
}
}
}
|
Methods
SelectItem
Summary
Selects item on the MultiSelect
Signature
| public bool SelectItem(string item)
|
Parameters
| Name | Type | Description |
| item | string | The item that will be selected on MultiSelect |
Return Value
bool
UnselectItem
Summary
Unselects item on the MultiSelect
Signature
| public bool UnselectItem(string item)
|
Parameters
| Name | Type | Description |
| item | string | The item that will be unselected on MultiSelect |
Return Value
bool
SelectItems
Summary
Selects items on the MultiSelect
Signature
| public void SelectItems(IEnumerable<string> items)
|
Parameters
| Name | Type | Description |
| items | IEnumerable | The items that will be selected on MultiSelect |
Return Value
void
UnselectItems
Summary
Unselects items on the MultiSelect
Signature
| public void UnselectItems(IEnumerable<string> items)
|
Parameters
| Name | Type | Description |
| items | IEnumerable | The items that will be unselected on MultiSelect |
Return Value
void
SelectAllItems
Summary
Selects all items on the MultiSelect
Signature
| public void SelectAllItems()
|
Return Value
void
UnselectAllItems
Summary
Unselects all items on the MultiSelect
Signature
| public void UnselectAllItems()
|
Return Value
void
AddItem
Summary
Adds a new item to the MultiSelect
Signature
| public bool AddItem(string item)
|
Parameters
| Name | Type | Description |
| item | string | The string value that will be added on MultiSelect |
Return Value
bool
RemoveItem
Summary
Removes an existing item from the MultiSelect
Signature
| public bool RemoveItem(string item)
|
Parameters
| Name | Type | Description |
| item | string | The string value that will be removed from MultiSelect |
Return Value
bool
RaiseSelectionItemsChanged
Signature
| internal void RaiseSelectionItemsChanged(IEnumerable<string> selectedItems)
|
Parameters
| Name | Type | Description |
| selectedItems | IEnumerable | |
Return Value
void
Accept
Signature
| internal void Accept(IChartControlVisitor visitor)
|
Parameters
| Name | Type | Description |
| visitor | IChartControlVisitor | |
Return Value
void
Properties
Items
Summary
Get the read-only copy of MultiSelect items
Signature
| public IReadonlyList<string> Items {get;}
|
Return Value
IReadonlyList
SelectedItems
Summary
Get the read-only copy of MultiSelect selected items
Signature
| public IReadonlyList<string> SelectedItems {get;}
|
Return Value
IReadonlyList
Events
SelectedItemsChanged
Summary
This event will trigger if the MultiSelect selected items changed
Signature
| public event Action<MultiSelectSelectedItemsChangedEventArgs> SelectedItemsChanged;
|