Defects of multi select of combobox

5 posts, 0 answers
  1. Yang
    Yang avatar
    5 posts
    Member since:
    Jun 2015

    Posted 05 Jul 2015 Link to this post

    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

  2. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 08 Jul 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yang
    Yang avatar
    5 posts
    Member since:
    Jun 2015

    Posted 24 Jul 2015 in reply to Nasko Link to this post

    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.
  5. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 28 Jul 2015 Link to this post

    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
  6. Yang
    Yang avatar
    5 posts
    Member since:
    Jun 2015

    Posted 28 Jul 2015 in reply to Nasko Link to this post

    Awesome. It works now. Thank you very much.
Back to Top
UI for WPF is Visual Studio 2017 Ready