This is a migrated thread and some comments may be shown as answers.

ComboBox items depending on tree level

5 Answers 65 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 16 Feb 2011, 10:32 AM
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

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 17 Feb 2011, 11:19 AM
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
0
Andreas
Top achievements
Rank 1
answered on 18 Feb 2011, 08:36 AM
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
0
Pavel Pavlov
Telerik team
answered on 21 Feb 2011, 02:46 PM
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!
0
Andreas
Top achievements
Rank 1
answered on 21 Feb 2011, 04:53 PM
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

0
Pavel Pavlov
Telerik team
answered on 21 Feb 2011, 05:22 PM
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!
Tags
TreeListView
Asked by
Andreas
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or