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

[Solved] GridView.SelectedItems.Add() trowing "Cannot change ObservableCollection during a CollectionChanged".... errors

1 Answer 357 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
m v klingeren
Top achievements
Rank 1
m v klingeren asked on 29 Nov 2010, 04:52 PM
I'm constantly getting an error when programmatically changing the selecteditems property of my grid
"Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event."

(with builds 1110 and 1119 latest Q3 hotfix) 

 

 

foreach
(CustomerItem csItem in csList.Where(csi=> csi.IsActive == true)) 
{    
if (GridRubrieken.Items.Contains(csItem)) 
        GridRubrieken.SelectedItems.Add(csItem);
  
}

I've tried to use a Dispatcher, "Dispatcher.BeginInvoke(new Action(() => .. etc..", without success
i'm trying to change the selecteditems property from a listbox > selectionchanged event. In which the user can make a selection, i'm then applying a selection, based on the IsActive setting.

There doesn't seem to be anything wrong with my code on first sight, it actually does work -sometimes...


Any ideas, we're trying to get our demo done, and getting ready to become your customer!

 

-edit: last thing i would like to mention, the grid is bound to a simple List or ObservableCollection, nothing fancy in this case.

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 02 Dec 2010, 12:38 PM
Hello m v klingeren,

Can you please replace this code:

if (GridRubrieken.Items.Contains(csItem)) 
        GridRubrieken.SelectedItems.Add(csItem);

with this one:

if (GridRubrieken.Items.Contains(csItem) && !GridRubrieken.SelectedItems.Contains(csItem))
        GridRubrieken.SelectedItems.Add(csItem);

Let us know if this helps.

Regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
m v klingeren
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or