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

Select item in treelistview from outside the control

2 Answers 16 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Sri
Top achievements
Rank 1
Sri asked on 06 May 2011, 06:40 PM
I am having trouble trying to set a collection of selected items on a treelist view, this is the way I am going about it.




foreach
 (var l in s)                 {                     df = new Assets.TreeListClass(l.filterName, l.filterId);                     df.Items.Add(new Assets.TreeListClass(l.filterDesc, l.filterElementId));                     obDataSelect.Add(df);                 }                 foreach (var gv in tlScenarioTypes.Items)                 {                     tlScenarioTypes.SelectedItems.Add(obDataSelect);                 }

error recieved
"Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event."

but went I run my app, I receive this error and I've looked all over the net and through the forums for assistance, so I'm needing help in figuring out what I'm do wrong. 

What I'm trying to do:
I have a grid that has a selection change event that fires, when it fires it triggers a wcf call that is populated to a collection that is already use to populate the treelistview.   Based the on the items received, I would like to have those items that are in the collection selected.  I already have a checkbox on the treelistview that can show selected.

Please help,

2 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 09 May 2011, 08:43 AM
Hello Jonathan,

May I ask you to place the following check before and its gets added to SelectedItem:

foreach (var gv in tlScenarioTypes.Items)
               {
                  if(!tlScenarioTypes.SelectedItems.Contains(obDataSelect)) {
                        tlScenarioTypes.SelectedItems.Add(obDataSelect);
                  }
               }

Alternatively, you could use our new selection methods Select and Deselect which have a performance benefit over using SelectedItems. For example:

foreach (var l in s)
                {
                    df = new Assets.TreeListClass(l.filterName, l.filterId);
                    df.Items.Add(new Assets.TreeListClass(l.filterDesc, l.filterElementId));
                    obDataSelect.Add(df);
                }
  
                tlScenarioTypes.Select(tlScenarioTypes.Items)
}


Greetings,
Milan
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
Sri
Top achievements
Rank 1
answered on 11 May 2011, 02:57 PM
I had a deadline to meet and I couldn't wait for an answer, so I just used the treeview and called it a day
Tags
TreeListView
Asked by
Sri
Top achievements
Rank 1
Answers by
Milan
Telerik team
Sri
Top achievements
Rank 1
Share this question
or