Finding the next and previous rows when grouping

2 posts, 0 answers
  1. Grant Fish
    Grant Fish avatar
    10 posts
    Member since:
    Apr 2010

    Posted 12 Jul 2011 Link to this post

    We are trying to logically determine the next row to select if the currently selected row disappears. Users can select a row and perform an operation that may or may not cause this row to reappear after the grid is refreshed. We cannot determine in advance if the currently selected row will be in the refreshed dataset, and we need to perform a full refresh to display new data that may have appeared for the user. If the current row is in the refreshed dataset, that is no problem. Each row contains a unique identifier in a hidden column and we can save the unique identifier and reselect this row after refreshing.

    The problem occurs if one or more of these rows disappear after a refresh. We want to move the selection to the previous row (right above the selection) as displayed to the user with sorting and grouping applied. How do we determine which row this would be?

    Basically, we need to be able to answer this question: Which row is visually displayed immediately above the currently selected row?

    We have it working for the most part, but the code is very complicated and still does not work exactly as we would like. For example, if the user selects the first row in a group and it disappears, the best that we can do is to go to the previous group and select the first row in that group. We would like to select the last row in the previous group. There are also problems if the entire group that contains the currenty selected row disappears.

    The GridNavigator won't help because I don't actually want to select the next or previous row. I just want to know which row I would select if I were to call the SelectPreviousRow or SelectNextRow methods, find the unique identifier value in this row, and store it to select the desired row after refreshing.
  2. Jack
    Jack avatar
    2333 posts

    Posted 15 Jul 2011 Link to this post

    Hello Grant,

    Thank you for contacting us. This is an interesting scenario. You can do the job by preserving the previous row just before refreshing the data source. The GridTraverser class may help in this case, please consider the following code snippet:
    GridViewRowInfo previousRow = null;
    GridTraverser traverser = new GridTraverser(this.radGridView1.MasterView);
    if (traverser.MoveForward(this.radGridView1.CurrentRow))
        if (traverser.MovePrevious())
            previousRow = traverser.Current;

    I hope this helps. If you have any further questions, do not hesitate to ask.

    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top