This is a migrated thread and some comments may be shown as answers.
Defects of multi select of combobox
4 Answers 7 Views
This is a migrated thread and some comments may be shown as answers.
Yang
Top achievements
Rank 1
Yang asked on 05 Jul 2015, 12:34 PM

Hi team,

I know it might not be a popular topic about multi select of combobox here. I read a lot of previous threads about multiple select, and finally can make it satisfy my requirement.  However, there is a defect of my implementation. I would try my best to describe my problem as clear as i can.

 I have two comboboxes, say A and B. The items of B are depending on what's selected in A. When the App starts up, I select a item, then the items of B refreshes correctly, and i can also select items in B without problems. Now the defect comes, i unselect the item and select some other items, the items in B still can refresh correctly. But, when i select items in now this time, the selectionBox is not changing any more, with a blank always. I don't know what i've been missing.

 I am creating a repository in github here git@github.com:hobbycamp/multicombobox.git. You guys can run it for real. Thanks for any help.

-Yang

4 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 08 Jul 2015, 12:56 PM
Hi Yang,

The observed by you behavior is caused by the clearing of the collection bound to the ComboBox's ItemsSource. When you clear it the SelectedIndex of the ComboBox is set to -1 and thus the DataContext of the "CheckableItemTemplate" becomes null. What we could suggest you is to bind the SelectedIndex property to a property inside your DataViewModel and when you clear the collection to set it back to 0 - thus everything should work as expected:
<telerik:RadComboBox x:Name="ComboBox2"
...
                    SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
...>
</telerik:RadComboBox>
private int selectedIndex ;
 
public int SelectedIndex
{
    get
    {
        return this.selectedIndex;
    }
 
    set
    {
        if (this.selectedIndex != value)
        {
            this.selectedIndex = value;
            this.OnPropertyChanged(() => this.SelectedIndex);
        }
    }
}
private void OnItem1Checked(object sender, NotifyCollectionChangedEventArgs e)
{
    this.Item2Collection.Clear();
    this.SelectedIndex = 0;
...
}

We hope this will help you.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Yang
Top achievements
Rank 1
answered on 24 Jul 2015, 03:55 PM
Sorry for the late reply, quite busy for now. I am so sorry that your solution doesn't work. See my pull request: https://github.com/hobbycamp/multicombobox/pull/1/files to make sure i've updated the right place.
0
Nasko
Telerik team
answered on 28 Jul 2015, 08:10 AM
Hi Yang,

It seems the proposed changes are made on the right place. The only difference is that inside the OnPropertyChanged you need to pass the property not the field as a parameter:
public int SelectedIndex2
{
    get
    {
        return this._selectedIndex2;
    }
    set
    {
        if(this._selectedIndex2 != value)
        {
            this._selectedIndex2 = value;
            this.OnPropertyChanged(() => this.SelectedIndex2);
        }
    }
}

Please, check the attached video that demonstrates how the proposed approach works on our side. I am also sending you your sample project with all the needed modifications made.

Hopes this helps.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Yang
Top achievements
Rank 1
answered on 29 Jul 2015, 02:03 AM
Awesome. It works now. Thank you very much.
Asked by
Yang
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Yang
Top achievements
Rank 1
Share this question
or