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

[Solved] Error when setting RadTreeViewItem.IsSelected = true

3 Answers 103 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Phil Cockfield
Top achievements
Rank 1
Phil Cockfield asked on 09 Oct 2009, 12:07 AM
I'm doing the following on the TreeView control:

        private void SetSelectedItemOnControl(ITreeNode item) 
        { 
            var treeItem = treeView.ItemContainerGenerator.ContainerFromItem(item) as RadTreeViewItem; 
            if (treeItem != null) treeItem.IsSelected = true
        } 
 

This successfully retrieves the 'treeItem' node (a RadTreeViewItem).

The next line however, when I set treeItem.IsSelected = true fails with the error:

     ArgumentException
     Value does not fall within the expected range.

Any ideas why?  In testing around with this, I can do other things on that item, like set toggling it's IsExpanded property successfully.  So it's in the visual tree, and seemingly functioning.

What to do?  Thanks!


3 Answers, 1 is accepted

Sort by
0
Phil Cockfield
Top achievements
Rank 1
answered on 13 Oct 2009, 12:07 AM
Hello?  Is there a solution to this?

I've tried doing it via data-binding (using details from this post: http://www.telerik.com/community/forums/silverlight/treeview/setting-quot-isexpanded-quot-on-templated-node.aspx) and I'm getting the same 'ArgumentException' error.

     ArgumentException
     Value does not fall within the expected range.

Thanks for any help you can give!!!
0
Valentin.Stoychev
Telerik team
answered on 13 Oct 2009, 05:51 AM
Hi Phil Cockfield,

Can you send us a simple project where this can be observed. You can open a support ticket and attach it there.

Thanks!

Greetings,
Valentin.Stoychev
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
Phil Cockfield
Top achievements
Rank 1
answered on 13 Oct 2009, 07:24 PM
OK - figured this out whilst extracting it out into a test project.  Not a problem with the control (opps).

I was trying to make this call before the control had fully loaded into the Visual Tree.  There must be a 'TransformToVisual' call somewhere in the changing of "IsSelected" - which requires the control to be loaded within the visual-tree...and that was the error.

Understand what's going on now.  Sorry for the confusion.  Thanks!
Tags
TreeView
Asked by
Phil Cockfield
Top achievements
Rank 1
Answers by
Phil Cockfield
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or