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

3 posts, 0 answers
  1. Scott
    Scott avatar
    12 posts
    Member since:
    Jun 2014

    Posted 19 Nov 2015 Link to this post

    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. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 24 Nov 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Scott
    Scott avatar
    12 posts
    Member since:
    Jun 2014

    Posted 08 Dec 2015 in reply to Dilyan Traykov Link to this post

    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);
                }
            }

Back to Top