ComboBox items depending on tree level

6 posts, 0 answers
  1. Andreas
    Andreas avatar
    23 posts
    Member since:
    Feb 2011

    Posted 16 Feb 2011 Link to this post

    Hello,

    is it possible to bind TreeListViewComboBox cell to different
    collections depending on the level in the Tree?
    The lists in the ComboBoxes would be different from the one used as
    source for the the TreeListView itself.

    Manay thanks in advance,

    Andreas
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Feb 2011 Link to this post

    Hello Andreas,

    It is possible .  The ComboBox column provides a mechanism for having a different ItemsSource even on each row.

    For this , you will need to use the ItemsSourceBinding property of the Column. Another thing you will need to do is to provide the source for the combo items in the business object itself.

    In details :
    Lets say you bind the TreeListView to a collection of "Continent" objets.
    You then  expose a Countries collection property on each Continent and for the combo column use : ItemsSourceBinding = {Binding Countries}.

    For your specific case : the collection property for different level items should contain different items .

    If all this sounds obscure, or you have troubles implementing it , just paste me the implementation of your data objects so that I can give a more specific example.

    All the best,
    Pavel Pavlov
    the Telerik team
  3. DevCraft banner
  4. Andreas
    Andreas avatar
    23 posts
    Member since:
    Feb 2011

    Posted 18 Feb 2011 Link to this post

    Hi,

    thank you for the explanation, I was able to implement this as described and it is working fine.

    Now in the next step I would like to catch the the event OnItemChange in the TreeListViewComboBox.
    I suppose I have to bind PropertyChanged somehow to my viewmodel but I don't know how. Here is my XAML code

                        <telerik:GridViewComboBoxColumn Header="Bezeichnung"
                                                        DataMemberBinding="{Binding AuswahlListeId, Mode=TwoWay}"
                                                        ItemsSourceBinding="{Binding AuswahlListe}"
                                                        SelectedValueMemberPath="Id"
                                                        DisplayMemberPath="ManagementEigenschaftName" />

    Could you explain me how to do that? I can give you more details of the project if needed.

    Many Thanks,

    Andreas
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 21 Feb 2011 Link to this post

    Hi Andreas,

    You have the following lie of code :
    DataMemberBinding="{Binding AuswahlListeId, Mode=TwoWay}"

    This binding is two way, so when the user changes the selected value, the setter of the AuswahlListeId would be called . You can perform your logic there ( in the setter) . Or if you prefer events , you can raise a PropertyChanged Event for the AuswahlListeId property( again there in the setter) , and handle it as needed.

    An alternative would be to handle the selection changed at the UI level . There is a way to listen for the bubbling routed selection changed event of the combo. You may see how to handle the selection changed event of any combo in RadGridView at point 3 of  this blogpost.
    something like :

    this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));


    In case you need additional assistance do not hesitate to contact me.

    All the best,
    Pavel Pavlov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  6. Andreas
    Andreas avatar
    23 posts
    Member since:
    Feb 2011

    Posted 21 Feb 2011 Link to this post

    Hi Pavel,

    this is how I try to catch the event OnItemChanged in the setter:

            public int AuswahlListeId
            {
                get { return _id; }
                set
                {
                    _idOld = _id;
                    _id = value;
                    _insertNode(_id, _idOld, _treeLevel);
                    OnPropertyChanged("AuswahlListeId");
                }

    But the code of the setter is executed after the GridViewComboBoxColumn has lost the focus.
    My goal is to catch the event when the Item selection was changed and I'm still in the ComboBox and I would prefer to do it in the viewmodel rather than in UI. Do you have any ideas?

    Regards,

    Andreas

  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 21 Feb 2011 Link to this post

    Hello Andreas,

    Your requirement of having the stuff done in the model gave me an idea.
    If you feed the combo with a CollectionViewSource ( binding to its default view) , then the current item will be synchronised for both - the collection view and the combo . This way when changing the selection in the combo , the  current item of the collection view would be changed.

    In other words the "AuswahlListe" property may be converted to a CollectionView source.
    Then at the model you can listen for changes in the current item of this collection view.

    Again - if you need a working  sample  for this - just let me know.

    Greetings,
    Pavel Pavlov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top
DevCraft banner