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

SelectionMode property not responding

3 Answers 90 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Miguel Rios
Top achievements
Rank 1
Miguel Rios asked on 31 Mar 2010, 11:19 PM
Hi to all,

I'll go directly to the problem... I am creating a treeView in the go from a flat list, i create one RadTreeVieIitem and if the item have child i add them to it with another function, and at the time if these child have child i add them to the previous items...

Now, the problem comes when i set the following properties as follow: IsOptionElementsEnabled = true, ItemsOptionListType = OptionListType.OptionList, SelectionMode = Telerik.Windows.Controls.SelectionMode.Single.

I would expect that only 1 RadTreeViewElement could be selected in the whole tree but that doesn't happen, in stead, the property SelectionMode = single only works for the child of each RadTreeViewItem, for example:

-Item1
-Item2
-Item4*
-Item5
-Item3
-Item6
-Item7*

here, only item4 or item5 can be selected at a time, but also item6 or item7, the asterics mean that they are selected I dont know if this is clear, i send a snipet of how i create the tree and the nodes

        public void createTree(RadTreeView rvTree, ObservableCollection<businessObject> obs) 
        { 
            try 
            {                 
                rvTree.Items.Clear(); 
                rvTree.SelectionMode = Telerik.Windows.Controls.SelectionMode.Single; 
                rvTree.IsOptionElementsEnabled = true
                rvTree.ItemsOptionListType = OptionListType.OptionList; 
 
 
                foreach (var a in obs) 
                { 
                    RadTreeViewItem tn = new RadTreeViewItem(); 
                     
 
 
                    tn.Header = a.Name;  //A property of my business object 
                     
 
                    if (a.IsSelected == true)  //Also a property of my business object 
                    { 
                        tn.CheckState = System.Windows.Automation.ToggleState.On; 
                        tn.IsSelected = true
 
                    } 
 
                    tn.Tag = a; 
 
                    if (a.Nodo_Padre == 0) //Proerty of my business object that indicates the key of the father item 
                    { 
                        rvTree.Items.Add(tn); 
                        addNodes(tn, this.obsUnAuditable); 
                    } 
 
                } 
            } 
            catch (Exception ex) 
            { 
                 
            } 
        } 
 
 
        public void addNodes(RadTreeViewItem rvItem, ObservableCollection<businessObject> obs) 
        {                          
            try   
            {   
                    var x = (businesobject)rvItem.Tag; //I saved my Business object in the tag of the RadTreeViewItem 
 
                    foreach (var y in obs) 
                    { 
                        if (y.Nodo_Padre == x.Clave)//Property that have the fathers key 
                        { 
                            RadTreeViewItem item = new RadTreeViewItem(); 
 
                            item.Header = y.Nombre; //property of my businessobject 
 
                            if (y.IsSelected == true) //Property of my business object 
                            { 
                                item.CheckState = System.Windows.Automation.ToggleState.On; 
                                item.IsSelected = true
                                item.Tag = y
                                rvItem.Items.Add(item); 
                                addNodes(item, this.obsUnAuditable); 
                            } 
                            else 
                            { 
                                item.Tag = y
                                rvItem.Items.Add(item); 
                                addNodes(item, this.obsUnAuditable); 
                            } 
                        } 
                    } 
            }   
            catch (Exception ex)   
            { 
 
            }   
        } 

the tree that i give the function createTree as a parameter is created in the .xaml file.

Hope yo can help me with this, its a crucial need in the development.


Thank you!

3 Answers, 1 is accepted

Sort by
0
Kiril Stanoev
Telerik team
answered on 01 Apr 2010, 01:15 PM
Hi Miguel,

Unfortunately I was not able to reproduce this issue. I've attached my test project. Could you please have a look at it and let me know if I am doing anything wrong. I'd be glad to further assist you.

Greetings,
Kiril Stanoev
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
Miguel Rios
Top achievements
Rank 1
answered on 01 Apr 2010, 11:32 PM
You did it good, what i meant is that i want only one item to be selected in the whole tree, in stead one item selected in each item... look, what i want is this:

-item1
-item2
-item5
-item6*(just this one selected in the whole tree)
-item3
-item7
-item8

and what the tree actually does is this:

-item1
-item2
-item5
-item6*(this is selected)
-item3
-item7*(but also this one is)
-item8

I tried to be as clear as possible, hope you got me, any doubt i'll try to exaplain it clearer.

Thank you!


0
Accepted
Tina Stancheva
Telerik team
answered on 07 Apr 2010, 02:00 PM
Hi Miguel Rios,

Please accept my apology for the delayed response.

I am not sure that I understood your scenario correctly. Do you want to allow the users to check only one item in the tree at once?

If this is what you need, then the SelectionMode property won't help you since it controls the number of selected items in your tree. When the property is set to Single, then only one item in the tree can have IsSelected=True at a time.

However, if you want to allow only one item to be checked at a time in the whole tree, you can modify the PreviewChecked()event handler to uncheck any previously checked items, like this:
while (treeView1.CheckedItems.Count > 0)
            {
                foreach (var o in treeView1.CheckedItems)
                {
                    RadTreeViewItem item = o as RadTreeViewItem;
                    if (item != null)
                    {
                        item.CheckState = System.Windows.Automation.ToggleState.Off;
                        break;
                    }
                }
            }


I attached the modified example. Can you please take a look at it and let me know if this is what you need?

Sincerely yours,
Tina Stancheva
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.
Tags
TreeView
Asked by
Miguel Rios
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Miguel Rios
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or