public void OnSourceActionBegin(ActionBeginEventArgs actionBeginEventArgs)
{
if (!string.IsNullOrEmpty(actionBeginEventArgs.EventName) && (actionBeginEventArgs.EventName.Equals("moveTo") || actionBeginEventArgs.EventName.Equals("moveAllTo")))
{
var selections = JsonConvert.DeserializeObject>>(actionBeginEventArgs.Items.ToString());
if (selections.Count + SelectedItems.Count > MaximumSelections)
{
actionBeginEventArgs.Cancel = true;
}
}
}
So that if the user was trying to add items that would result in the capacity being exceeded we simply do nothing. However in this case it doesn't look like actionBeginEventArgs.Cancel = true actually cancels the operation (the item still moves from box 1 to box 2).
Further, is there a way to override the default styling on the toolbar? I would like to disable the buttons if the right box is already at capacity.
Thanks!
<div class="dual-list-groupa">
<h4> Group A</h4>
<SfListBox ID="listbox1" @bind-Value="@Value" Scope="#listbox2" DataSource="@GroupA" TItem="ListData" Height="330px" TValue="string[]" MaximumSelectionLength="3">
<ListBoxFieldSettings Text="Name"></ListBoxFieldSettings>
<ListBoxSelectionSettings ShowCheckbox="true"></ListBoxSelectionSettings>
<ListBoxToolbarSettings Items="@Items"></ListBoxToolbarSettings>
</SfListBox>
</div>
<div class="dual-list-groupb">
<h4>Group B</h4>
<SfListBox ID="listbox2" DataSource="@GroupB" Height="330px" TItem="ListData" TValue="string[]" MaximumSelectionLength="3">
<ListBoxSelectionSettings ShowCheckbox="true"></ListBoxSelectionSettings>
<ListBoxFieldSettings Text="Name"></ListBoxFieldSettings>
</SfListBox>
</div> |
<div class="dual-list-groupa">
<h4> Group A</h4>
<SfListBox @ref="listboxObj1" ID="listbox1" Scope="#listbox2" DataSource="@GroupA" TItem="ListData" Height="330px" TValue="string[]" @bind-Value="SelectValue">
<ListBoxFieldSettings Text="Name" Value="Name"></ListBoxFieldSettings>
</SfListBox>
</div>
<div style="width:110px;margin:5%" class="e-listbox-tool ">
<SfButton OnClick="@moveUp" IconCss="e-icons e-moveup">Move Up</SfButton>
<SfButton OnClick="@moveDown" IconCss="e-icons e-movedown">Move Down</SfButton>
<SfButton OnClick="@moveTo" IconCss="e-icons e-moveto" Disabled="moveToDisabled">Move To</SfButton>
<SfButton OnClick="@moveFrom" IconCss="e-icons e-movefrom">Move From</SfButton>
<SfButton OnClick="@moveAllTo" IconCss="e-icons e-moveallto" Disabled="true">Move All To</SfButton>
<SfButton OnClick="@moveAllFrom" IconCss="e-icons e-moveallfrom">Move All From</SfButton>
</div>
<div class="dual-list-groupb">
<h4>Group B - Capacity 5 Items</h4>
<SfListBox @ref="listboxObj2" ID="listbox2" DataSource="@GroupB" TItem="ListData" Height="330px" TValue="string[]">
<ListBoxFieldSettings Text="Name" Value="Name"></ListBoxFieldSettings>
</SfListBox>
</div>
@code {
private bool moveToDisabled = false;
private async Task moveAllTo()
{
var DataList = await listboxObj1.GetDataList();
if (DataList.Count() > 0)
{
await listboxObj1.MoveAllTo();
}
}
private async Task moveAllFrom()
{
var DataList = await listboxObj2.GetDataList();
if (DataList.Count() > 0)
{
await listboxObj2.MoveAllTo(listboxObj1.ID);
}
}
private async Task moveUp()
{
await listboxObj1.MoveUp();
}
private async Task moveDown()
{
await listboxObj1.MoveDown();
}
private async Task moveTo()
{
var DataList = await listboxObj1.GetDataList();
var DataList2 = await listboxObj2.GetDataList();
if ((SelectValue.Count() + DataList2.Count) > 5)
{
await JsRuntime.InvokeAsync<bool>("confirm", "Group B Listbox Capacity 5 items");
} else if (DataList.Count() > 0)
{
await listboxObj1.MoveTo();
}
DataList2 = await listboxObj2.GetDataList();
if (DataList2.Count() == 5)
{
moveToDisabled = true;
}
}
private async Task moveFrom()
{
var DataList = await listboxObj2.GetDataList();
if (DataList.Count() > 0)
{
await listboxObj2.MoveTo(listboxObj2.Value, null, listboxObj1.ID);
}
DataList = await listboxObj2.GetDataList();
if (DataList.Count() < 5)
{
moveToDisabled = false;
}
}
} |