If i just initialize List<MyClass> _listSignetRapport { get; set; } = new List<MyClass>(); the AddDataToList buttons doesn't add element to listbox
But if initialize like this List<MyClass> _listSignetRapport { get; set; } = new List<MyClass>(){ new MyClass { CodeType = 2, Correspondance = "testt", Source = "SignetN123" } }; the AddDataToList buttons add element to listbox
Q2: How to remove SelectedItems in ListBox considering single or multiple Selection
<div class="form-row">
<div class="col-5">
<SfComboBox @ref="_signetDdlObj" TItem="string" TValue="string" @bind-Value="_signetValue" Placeholder="Signets disponibles" AllowCustom="true" DataSource="@_signetsList" AllowFiltering="true" IgnoreAccent=true >
<ComboBoxEvents TValue="string" Filtering="OnDdlFiltering"></ComboBoxEvents>
<ComboBoxTemplates TItem="string">
<NoRecordsTemplate>
<div>
<div id="nodata"> Ajouter dans la liste?</div>
<button id="btn" class="e-control e-btn" @onclick="@UpdateDdlValue">Ajouter</button>
</div>
</NoRecordsTemplate>
</ComboBoxTemplates>
</SfComboBox>
</div>
<div class="col-5">
<SfDropDownList @bind-Value="_infosourceValue" TValue="string" TItem="string" Placeholder="Informations sources" DataSource="@_infoSourceList" AllowFiltering=true IgnoreAccent=true >
</SfDropDownList>
</div>
<SfButton CssClass="e-round" IconCss="e-icons e-plus-icon" IsPrimary="true" @onclick="AddDataToList"></SfButton>
</div>
<br/>
<div>
<SfListBox TValue="string[]" TItem="MyClass" @ref="_listBoxSignetObj" DataSource="_listSignetRapport">
<ListBoxSelectionSettings Mode="SelectionMode.Multiple"></ListBoxSelectionSettings>
<ListBoxFieldSettings Text="Correspondance" Value="Source" />
</SfListBox>
</div>
<br />
<div class="form-group" style="text-align:right;">
<span>
<input type="submit" class="btn btn-default" value="Supprimer" @onclick="RemoveDataToList"/>
<input type="submit" class="btn btn-success" value="Enregistrer" />
<input type="reset" class="btn btn-danger" @onclick="@(() => ClosePilotage())" value="Annuler" />
</span>
</div>
@code{
private SfListBox<string[], MyClass> _listBoxSignetObj;
SfComboBox<string, string> _signetDdlObj;
List<string> _signetsList { get; set; } = new List<string>() { "CPOSTAL", "dob", "city", "name", "chir" };
List<string> _infoSourceList { get; set; } = new List<string>(){ "Code Postal", "Nom et Prenom", "Date et lieu de naissance", "Ville et quartier"};
string _signetValue { get; set; }
string _infosourceValue { get; set; }
private string _enteredText { get; set; }
List<MyClass> _listSignetRapport { get; set; } = new List<MyClass>(){ new MyClass { CodeType = 2, Correspondance = "testt", Source = "SignetN123" } };
public void OnDdlFiltering(FilteringEventArgs e)
{
_enteredText = e.Text;
}
public void UpdateDdlValue()
{
var newItem = new List<string>() { _enteredText };
_signetDdlObj.AddItem(newItem);
_signetDdlObj.HidePopup();
}
private void AddDataToList()
{
var signetRapport = new MyClass() { CodeType = 2, NomSignet = _signetValue, InformationSource = _infosourceValue };
_listSignetRapport.Add(signetRapport);
_listBoxSignetObj.AddItems(signetRapport);
}
private void RemoveDataToList()
{
_listBoxSignetObj.RemoveItems(); // need to implement removeSelectedItems
}
public class MyClass
{
public int CodeType { get; set; }
public string Source { get; set; }
public string Correspondance { get; set; }
}
}
Chimène NK.