Select item in treelistview from outside the control

3 posts, 0 answers
  1. Sri
    Sri avatar
    7 posts
    Member since:
    Jan 2011

    Posted 06 May 2011 Link to this post

    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. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 09 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Sri
    Sri avatar
    7 posts
    Member since:
    Jan 2011

    Posted 11 May 2011 Link to this post

    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
Back to Top