Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
330
Setting selected items
posted

With the control like this:

this.xmceEntities.AllowMultipleSelection = true;
this.xmceEntities.DisplayMemberPath = "CompanyId";
this.xmceEntities.CheckBoxVisibility = Visibility.Visible;

To get selected data works perfectly with the property SeledtedItems

But when we need to set them i use a code like this:

/// <summary>

/// List of selected entities
/// </summary>
public override IList<Company> SelectedEntities
{
get
{
    ....
}
set
{
this.xmceEntities.SelectedItems.Clear();
foreach (var item in value)
{
this.xmceEntities.SelectedItems.Add(item);
}

....

}
}

The display text show the companies ids as selected:

[1, 3, 5       ]

But in dropdown no one have the checkbox selected.

Parents
  • 330
    Suggested Answer
    posted

    For some reason i did this to work:


    this.xmceEntities.SelectedItems.Clear();

    if (value != null)
    {
    foreach (var item in value)
    {
    var selectedCompany = this.xmceEntities.ItemsSource
    .Cast<Company>().SingleOrDefault(x => x.CompanyId == item.CompanyId);

    if (selectedCompany != null)
    {
    this.xmceEntities.SelectedItems.Add(selectedCompany);
    }
    }

Reply Children
No Data