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

Selecting Children Rows

5 Answers 119 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
lori guymon
Top achievements
Rank 1
lori guymon asked on 05 Apr 2011, 09:17 PM
I have a simple TreeListView with just two levels (think product for level 1 and components for level 2).  It contains a GridViewSelectColumn so that users can select a product and one or more components associated with the product.  When the user selects a product, I want to programically select all of the components (so by default they don't have to individually select them) and for those components that have a property called "required" set to true, I want to not only select it but disable or make it read-only so that the user cannot unselect it if the parent (product) is selected.  In addition, if the user unselects a product, I will want to unselect all children (components).

I thought this would be pretty simple but I'm stumped on an elegant solution or am making it harder than it really is.  Can anyone help me?
Thank you!

5 Answers, 1 is accepted

Sort by
0
lori guymon
Top achievements
Rank 1
answered on 05 Apr 2011, 11:58 PM
I have tried to use the SelectionChanged event to accomplish what I want.  I am successfully able to expand the parent row to expose the children rows and am able to add\remove children records from the tree's SelectedItems collection just fine. 

I'm just having issues with disabling\enabling the selection column based on the property value (Required in this case) of the CatalogProduct which is bound to the tree.  Even when the column appears to be disabled, I can still click on the checkbox and, of course, the column background is shaded gray when what I really just want the checkbox to be disabled.   Here is my code:

public void CatalogProductsSelectionChanged(object sender, SelectionChangeEventArgs e) {
  
            var tree = (RadTreeListView) sender;
  
            if (e.AddedItems.Count > 0) {
                var item = e.AddedItems[0];
                var parent = (CatalogProduct) item;
  
                //if children exist, expand hierarchy in tree control
                if (parent.ChildrenCatalogProducts.Count > 0) {
                    tree.ExpandHierarchyItem(item);
  
                    //find row corresponding to child and add to tree's SelectedItems
                    //collection. Disable selectcolumn if child
                    //has Required property set to true
                    foreach (var child in parent.ChildrenCatalogProducts) {
                        var row = tree.ItemContainerGenerator.ContainerFromItem(child) as TreeListViewRow;
                        tree.SelectedItems.Add(child);
                        if (row != null) {
                            row.Cells[0].IsEnabled = !child.Required;
                        }
                    }
                }
            }
  
            if (e.RemovedItems.Count > 0)
            {
                var item = e.RemovedItems[0];
                var parent = (CatalogProduct)item;
  
                //if children exist, collapse hierarchy in tree control
                if (parent.ChildrenCatalogProducts.Count > 0) {
                    tree.CollapseHierarchyItem(item);
  
                    //Remove child item from Tree's SelectedItems and find 
                    //row corresponding to child and enable its select column
                    foreach (var child in parent.ChildrenCatalogProducts) {
                        var row = tree.ItemContainerGenerator.ContainerFromItem(child) as TreeListViewRow;
                        tree.SelectedItems.Remove(child);
                        if (row != null) {
                            row.Cells[0].IsEnabled = true;
                        }
                    }
                }
            }
        }

I know that the ItemContainerGenerator method to grab the rows is not the way to go but I can't figure out an alternative. 

Any advice?
0
Accepted
Ivan Ivanov
Telerik team
answered on 08 Apr 2011, 01:52 PM
Hi lori guymon,

I have prepared a sample project for you. Please, refer to it and inform us if this approach meets your requirements.

Greetings,
Ivan Ivanov
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
lori guymon
Top achievements
Rank 1
answered on 11 Apr 2011, 07:29 PM
Hi Ivan,
Thank you so much for the sample app.  That provided me with the technique I needed to finish what I wanted to do. 
Thanks again!
0
Ehsan
Top achievements
Rank 1
answered on 01 Nov 2014, 06:16 AM
hi
i have a table with this structure:   (p_Id , p_Title , p_upper_pId)

i want to view this table in radtreelistview as hierachy style.
please show me a simple example to do this.
tnx
0
Ivan Ivanov
Telerik team
answered on 05 Nov 2014, 05:31 PM
Hi,

Would it possible for you to open a support ticket and set us a sample dummy project that illustrates your data model? Thus we will be able to closely inspect your scenario and provide an appropriate solution. Thank you.

Regards,
Ivan Ivanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeListView
Asked by
lori guymon
Top achievements
Rank 1
Answers by
lori guymon
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Ehsan
Top achievements
Rank 1
Share this question
or