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

CollectionViewSource as ItemSource problem

8 Answers 298 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Erik Rydgren
Top achievements
Rank 2
Erik Rydgren asked on 06 Sep 2009, 05:28 PM
Hi!

I am evaluating Teleriks Silverlight controls to see if it fits our companys needs. So far it is looking good but I'm having trouble with the RadComboBox. I use a CollectionViewSource derived class and give the RadComboBox an ICollectionView as ItemSource. The combo gets populated as expected and the SelectedValue and SelectedValuePath is working as expected.

But when I select an item in the combobox it seems like it fails to update CurrentItem in the CollectionViewSource and hence I don't get any CurrentChanged event in my ViewModel.

Does RadComboBox support ICollectionView as ItemSource or is it treating it as any other IEnumerable?

/ Regards
Erik Rydgren
Senior Developer
Aptic AB

Edit:
Was simple enough to fix

        comboBox.SelectionChanged += (sender, args) => {
          if (comboBox is RadComboBox) {
            RadComboBox combo = sender as RadComboBox;
            if (combo.ItemsSource is ICollectionView) {
              ICollectionView collectionView = combo.ItemsSource as ICollectionView;
              collectionView.MoveCurrentTo(combo.SelectedItem);
            }
          }
        };

Any possibility that we can have the standard control behave like this? In the meantime I will have to overload it.

8 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 07 Sep 2009, 08:35 AM
Hi Erik,

RadComboBox treats all items sources as IEnumerable, hence it does not automatically update ICollectionView if such is provided. This looks like a nice feature, so I will add it to the product backlog. We will include it in the upcoming major release Q3 2009, scheduled after less than two months.

Your points have been updated.

Regards,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Erik Rydgren
Top achievements
Rank 2
answered on 07 Sep 2009, 10:58 AM
That sounds great.

What is the status regarding support for ICollectionView and your other controls? Like single select listboxes and treeviews?

/ Erik

0
Valeri Hristov
Telerik team
answered on 07 Sep 2009, 11:06 AM
Hello Erik,

I don't think we have controls that update ICollectionView automatically, except RadGridView. As far as I know, this feature is not on the list for RadTreeView and we don't have other selection controls, except Date/TimePicker, but they are not data-bound anyway. Let me know if you need this feature for other controls and I will forward your request to the corresponding development teams.

Best wishes,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Erik Rydgren
Top achievements
Rank 2
answered on 07 Sep 2009, 11:32 AM
Thanks for the answers. Nice to see that you are fast on the ball.

I don't have the need as of now, it was more of a general question. Knowing that there is support in the gridview is good. I try to keep my ViewModels as oblivious as possible about what controls the view is using to present the data.

In utopia the ViewModel won't even know that there even exists such a thing as a View.

For instance what I needed the functionality of ICollectionView in RadComboBox:
Collection Alist is a CollectionViewSource of A objects.
Collection Blist is a CollectionViewSource of B objects.
Each B object has an A parent denoted by a foreign key relationship.
If I want to enforce rule that Blist only contains B objects that has the currently selected A in Alist as parent then I can handle it all in the ViewModel.

On Alist.CurrentChanged -> Refresh Blist
Blist.filter -> Only accept B's that has Alist.SelectedItem as parent.

No need for the ViewModel to know what moves Alist.CurrentItem and who displays the Blist items.
Alist can be displayed in a combo/list/grid/form. The ViewModel don't know and don't care.

The business rule is enforced anyway. You can't select/view B's from any other A than the currently selected one.

/ Erik

0
Manuel Felício
Top achievements
Rank 1
answered on 25 Mar 2010, 06:08 PM
Hi,

We are moving to Q1 2010 (v 309.1030) and this feature isn't implemented. Microsoft Combobox's work like a charm with ICollectionView implementations. In fact, I think all controls that support an ItemsSource property work well with ICollectionView.

Since Q2 2009 that we have been using our own RadGridView derived class that added some support for ICollectionView. We just moved to Q1 and found that, so far, everything is working as expected with RadGridView and ICollectionView.

In this case, it makes sense to have RadComboBox working with ICollectionView (at least a synchronization with the CurrentItem) in both directions -> view to collectionView, collectionView to view.

What are your plans for this?

Thanks,

MF.
0
Valeri Hristov
Telerik team
answered on 29 Mar 2010, 01:41 PM
Hi Manuel,

Currently the development of this feature is not scheduled, but since we are getting requests for it we will consider it for the near future. As far as I know, there are technical issues for the implementation, so it is not an easy feature that can be added immediately, but you could watch our progress here:
http://www.telerik.com/support/pits.aspx#/public/silverlight/1588

Best wishes,
Valeri Hristov
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Denis Vuyka
Top achievements
Rank 1
answered on 30 Mar 2010, 02:27 PM
Guys, so much time after this problem was highlighted and it is still not even scheduled!
0
Manuel Felício
Top achievements
Rank 1
answered on 05 Apr 2010, 05:27 PM
Well, this is what I've done as a workaround:

    public class MyRadComboBox : RadComboBox  
    {  
        /// <summary> 
        /// Invoked when the <see cref="P:System.Windows.Controls.ItemsControl.Items"/> property changes.  
        /// </summary> 
        /// <param name="e">Information about the change.</param> 
        protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)  
        {  
            base.OnItemsChanged(e);  
            if (this.ItemsSource != null  
                && e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset  
                && this.ItemsSource is ICollectionView)  
            {  
 
                (this.ItemsSource as ICollectionView).CurrentChanged += CollectionView_CurrentChanged;  
            }  
        }  
 
        /// <summary> 
        /// Handles the CurrentChanged event of the CollectionView control.  
        /// </summary> 
        /// <param name="sender">The source of the event.</param> 
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 
        void CollectionView_CurrentChanged(object sender, EventArgs e)  
        {  
            var collectionView = this.ItemsSource as ICollectionView;  
            if (collectionView != null && this.SelectedItem != collectionView.CurrentItem)  
                this.SelectedItem = collectionView.CurrentItem;  
        }  
 
        /// <summary> 
        /// Called when the selection changes.  
        /// </summary> 
        /// <param name="e">The event data.</param> 
        protected override void OnSelectionChanged(System.Windows.Controls.SelectionChangedEventArgs e)  
        {  
            base.OnSelectionChanged(e);  
            if (this.SelectedItem == null || !(this.ItemsSource is ICollectionView)) return;  
            var collectionView = this.ItemsSource as ICollectionView;  
            if (collectionView.CurrentItem != this.SelectedItem)  
                collectionView.MoveCurrentTo(this.SelectedItem);  
        }  
    }  
 

I hope you find it useful.
Tags
ComboBox
Asked by
Erik Rydgren
Top achievements
Rank 2
Answers by
Valeri Hristov
Telerik team
Erik Rydgren
Top achievements
Rank 2
Manuel Felício
Top achievements
Rank 1
Denis Vuyka
Top achievements
Rank 1
Share this question
or