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

How to get the CURRENTLY visible rows after group has been expanded then collapsed

2 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 19 Nov 2015, 02:24 PM

Hello,

 I need to get the visible rows. I've seen how to do this by way of: theGrid.ChildrenOfType<GridViewRow>();

But this seems to have a flaw. If I expand a group and then collapse that group, the rows in the group are now returned as visible.

Is there a way to get only the currently visible rows?

 Thanks,

Scott

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 24 Nov 2015, 12:43 PM
Hello Scott,

Are you using the Grouping Events - GroupRowIsExpandedChanging and GroupRowIsExpandedChanged?

The the.grid.ChildrenOfType<GridViewRow>() returns the rows which are currently added to the grid. The rows get added when you expand the group, but are not removed when you collapse it.

As stated in this article, generally we do not recommend working with the visual elements as RadGridView is a virtualized control and its elements are reused as they go in and out the visual area. You can check the topic on UI virtualization for further information. Here are some other helpful articles regarding RadGridView performance - Degraded Performance and Tips and Tricks.

Your best bet would be to use the GroupRowIsExpandedChanged event and access its e.Row.Items.
Add the items to the collection if e.Row.IsExpanded, remove them otherwise and you're good to go. 

Let me know if this works for you.

Regards,
Dilyan Traykov
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Scott
Top achievements
Rank 1
answered on 08 Dec 2015, 03:25 PM

Thanks! That worked great.

 For others:

 1 - GroupRowIsExpandedChanged event

2 - Check if e.Row.IsExpanded

3 - Add or Remove e.Row.Group.Items from your own separately maintained list.

Mine looked like this:

private void EmployeeTopRadDataGrid_GroupRowIsExpandedChanged(object sender, GroupRowEventArgs e)
        {
            if (e.Row.IsExpanded)
                GroupingList.AddRange(e.Row.Group.Items.OfType<TimeSheet>().ToList());
            else
            {
                foreach (TimeSheet ts in e.Row.Group.Items.OfType<TimeSheet>().ToList())
                    GroupingList.Remove(ts);
            }
        }

Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Scott
Top achievements
Rank 1
Share this question
or