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

MULTIPLE SELECTIONS IN RADLISTBOX USING MVVM

3 Answers 197 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Shruti
Top achievements
Rank 1
Shruti asked on 13 Aug 2013, 12:24 PM
Hi,
I have a query.I am developing WPF app and using MVVM Architecture.
 I have a RadListbox which gives the option of selecting multiple items.I want to access the selected items in my Viewmodel. How do i do it??

Thanks in advance

Shruti

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 14 Aug 2013, 03:25 PM
Hi Shruti,

I would suggest that you check the following blog post which explains how to achieve the needed approach:
http://blogs.telerik.com/xamlteam/posts/13-01-14/extending-the-functionality-of-radcontrols-with-attached-properties

Regards,
Yana
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
David
Top achievements
Rank 1
answered on 13 Feb 2014, 10:01 AM
Unfortunately the code in the blog post is a bit buggy.
The first selection is off.

Also, it's not generic.
0
Yana
Telerik team
answered on 18 Feb 2014, 11:41 AM
Hi David,

The issue with the initial selection is already logged in our Feedback Portal, you can track its progress at the following link:
http://feedback.telerik.com/Project/143/Feedback/Details/118799-using-an-attached-property-to-populate-the-selecteditems-of-the-control-initially

As a workaround you could simply set the SelectedItems in the Loaded event of the control rather than in the ViewModel:

private void ListBox_Loaded(object sender, RoutedEventArgs e)
{
     var items = this.ListBox.ItemsSource as ObservableCollection<Country>;
     this.MyViewModel.SelectedCountries = new System.Collections.ObjectModel.ObservableCollection<Country>()
     {
    items[4],
    items[5],
    items[6],
    items[7]
     };
}

I hope this helps.

Regards,
Yana
Telerik
Tags
ListBox
Asked by
Shruti
Top achievements
Rank 1
Answers by
Yana
Telerik team
David
Top achievements
Rank 1
Share this question
or