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

Access to children rows for row

1 Answer 244 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pawel
Top achievements
Rank 1
Pawel asked on 13 May 2014, 01:59 PM
Hello

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

1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 13 May 2014, 04:14 PM
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.
 
Tags
GridView
Asked by
Pawel
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or