Access to children rows for row

2 posts, 0 answers
  1. Pawel
    Pawel avatar
    39 posts
    Member since:
    Apr 2014

    Posted 13 May 2014 Link to this post

    Hello

    How can I access to rows for specific row in parent-children relation? Something like:
    gridView.Rows[1].Childrens (type IEnumerable<GridViewRow>)
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 13 May 2014 Link to this post

    Hello Pawel,

    I'm not sure what you mean by How can I access to rows for specific row. There are a lot of scenario specific approaches to access the GridView items. For example you can use the Loaded event of the GridView to get the already loaded items in the Items collection. Please note that the items in the collection are your Business objects (in the code snippet CompanyInfo class).

    private void xGridView_Loaded(object sender, RoutedEventArgs e)
            {
                var gridView = sender as RadGridView;
                List<CompanyInfo> compaanies = new List<CompanyInfo>();
     
                 
                foreach (CompanyInfo item in gridView.Items)
                {
                    compaanies.Add(item);
                }
            }

    Another case is if you have a hierarchical GridView and you want to access the hierarchical items. For example if you have a hierarchical GridView and expand the row with index 5 and click a button with the event handler as shown below in the code snippet you will get all the b for the selected row. This is done by using the ItemContainerGenerator.ContainerFromItem() method to get the container for the row. Then you can use the ChildrenOfType<GridViewRow>() method to get all the child rows.

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                var item = this.xGridView.Items[5];
                var row = this.xGridView.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow;        
     
                var childRows = row.ChildrenOfType<GridViewRow>();
            }


    In order to advise you better could you please go into detail about your case and what you need to achieve with the rows ?

    We are looking forward to your response.

    Regards,
    Boris Penev
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top