|
|
|
@using System.Collections.ObjectModel
<div class="control-section">
<div class="control_wrapper">
<div id='content'>
<div>
<h4> Default Mode</h4>
<SfMultiSelect TValue="string[]" @bind-Value="mylist" Mode="@VisualMode.Default" Placeholder="Favorite Sports" DataSource="@Games">
<MultiSelectFieldSettings Text="Text" Value="ID"></MultiSelectFieldSettings>
</SfMultiSelect>
</div>
</div>
</div>
</div>
<button type="button" @onclick="setGames">Set Games</button>
@code{
public class GameFields
{
public string ID { get; set; }
public string Text { get; set; }
}
private List<GameFields> Games = new List<GameFields>()
{
new GameFields(){ ID= "Game1", Text= "American Football" },
new GameFields(){ ID= "Game2", Text= "Badminton" },
new GameFields(){ ID= "Game3", Text= "Basketball" },
new GameFields(){ ID= "Game4", Text= "Cricket" },
new GameFields(){ ID= "Game5", Text= "Football" },
new GameFields(){ ID= "Game6", Text= "Golf" },
new GameFields(){ ID= "Game7", Text= "Hockey" },
new GameFields(){ ID= "Game8", Text= "Rugby"},
new GameFields(){ ID= "Game9", Text= "Snooker" },
new GameFields(){ ID= "Game10", Text= "Tennis"},
};
string[] mylist = new string[] { };
private void setGames()
{
mylist = new string[] { "Game5", "Game6" };
}
}
|
|
private void setGames()
{
var newValue = new List<string>(mylist);
newValue.Add("Game6"); //Does not work!!!
newValue.Add("Game5"); //Does not work!!!
mylist = newValue;
} |