Selecting Children Rows

6 posts, 1 answers
  1. lori guymon
    lori guymon avatar
    23 posts
    Member since:
    May 2004

    Posted 05 Apr 2011 Link to this post

    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!
  2. lori guymon
    lori guymon avatar
    23 posts
    Member since:
    May 2004

    Posted 05 Apr 2011 Link to this post

    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?
  3. DevCraft banner
  4. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 08 Apr 2011 Link to this post

    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
  5. lori guymon
    lori guymon avatar
    23 posts
    Member since:
    May 2004

    Posted 11 Apr 2011 Link to this post

    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!
  6. Ehsan
    Ehsan avatar
    10 posts
    Member since:
    Nov 2014

    Posted 01 Nov 2014 Link to this post

    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
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 05 Nov 2014 Link to this post

    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.

     
Back to Top
DevCraft banner