Search a Hierarchical Grid

8 posts, 2 answers
  1. Ingo
    Ingo avatar
    15 posts
    Member since:
    Apr 2016

    Posted 13 Apr Link to this post

    Hello,

    I use a hierarchical grid in my application. The grid has a master level and a child level.

    I like the integrated search function of the grid and want to use it in my project.

    I have a problem when I use the UseScrollbarsInHierarchy feature of the grid.

    When I set it to False the search function works fine which means the table scrolls to each search hit (child and master hit alike) when the arrow buttons next to the search field are used.

    When I set it to True (desired option because the child level can have several hundred rows) the grid does not scroll to the search hits anymore.

    How can I achieve that the master scrollbar scrolls to the search hit and the child scroll bar too?

    I tried using Databinding / Object Relational Mode / Load On Demand with the same result as described above.

     

    I use the latest version of the UI for WinForms with .NET 3.0 (Unfortunately the highest version of target System).

     

    Thanks for your help.

    Regard

    Ingo

     

  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 13 Apr Link to this post

    Hello Ingo,

    Thank you for writing.

    I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    I have also updated your Telerik points.

    Currently, the possible solution that I can suggest is to use the UseScrollbarsInHierarchy property set to false.

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ingo
    Ingo avatar
    15 posts
    Member since:
    Apr 2016

    Posted 13 Apr Link to this post

    Hello,

    thank You for Your quick response.

    Is it possible to use a workaround for the UseScrollbarsInHierarchy = True option to scroll with the search results? e.g. use an event and manually scroll master and child level?

    Regards

    Ingo

  5. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 13 Apr Link to this post

    Hello Ingo,

    Thank you for writing back. 

    You can subscribe to the CurrentRowChanged event and scroll to the specific row programmatically. It is necessary to scroll to its parent row as well.
    private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
    {
        if (this.radGridView1.CurrentRow != null)
        {
            if (this.radGridView1.CurrentRow.HierarchyLevel > 0)
            {
                tableElement.ScrollToRow((GridViewHierarchyRowInfo)(this.radGridView1.CurrentRow).Parent);
                this.radGridView1.TableElement.EnsureRowVisible((GridViewHierarchyRowInfo)(this.radGridView1.CurrentRow).Parent);
                tableElement.ScrollToRow(this.radGridView1.CurrentRow);
                tableElement.EnsureRowVisible(this.radGridView1.CurrentRow);
            }
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Ingo
    Ingo avatar
    15 posts
    Member since:
    Apr 2016

    Posted 13 Apr Link to this post

    Hello,

    this workaround works very well! Thank You!

    I added a check for visibility to prevent the table from "Jumping" when the user clicks a row with the mouse or scrolls with the arrow keys through the data.

    if (!this.radGridView1.CurrentRow.IsVisible)  
    {            
        if (this.radGridView1.CurrentRow.HierarchyLevel > 0)                  
        {
        ...
        }
    }
    Thank You again!

    Regards,

    Ingo

  7. Ingo
    Ingo avatar
    15 posts
    Member since:
    Apr 2016

    Posted 14 Apr Link to this post

    Hello,

    I have two additional questions / remarks to this problem. My previous solution (with .IsVisible) in my previous post did not work as expected.

    1.) I wanted to check if the current row is / was already in the view area of the user. This is necessary because if the user clicks a row the whole grid "Jumps" and the clicked element is shown at first entry in the grid. This can be a little bit confusing. How can be achieved to use the scroll solution for the search without triggering the event when user navigates the grid with the mouse or keyboard?

    2.) I encountered a performance issue with the above solution when the user scrolls through a child table with the keyboard down arrow. When the current row reaches the last displayed row of a child table (see attachment) and the next press on the down arrow would lead the child table to scroll down this takes a very long time to scroll. I identified the line

    this.radGridView1.TableElement.ScrollToRow(this.radGridViewFile.CurrentRow);

    to be the source so I commented it out. Then the solution still works with the search and the navigation with the keyboard is smooth again.

    Thank You!

    Regards

    Ingo

  8. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 14 Apr Link to this post

    Hello Ingo,

    Thank you for writing back. 

    You can detect when the CurrentRowChanged event is triggered by the next/previous navigation in the search row. For this purpose, subscribe to the GridSearchCellElement's FindNextButton.MouseDown and FindPreviousButton.MouseDown events:
    private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
    {
        if (this.radGridView1.Tag == "search" && this.radGridView1.CurrentRow != null)
        {
            this.radGridView1.Tag = null;
            if (this.radGridView1.CurrentRow.HierarchyLevel > 0)
            {
                tableElement.ScrollToRow((GridViewHierarchyRowInfo)(this.radGridView1.CurrentRow).Parent);
                this.radGridView1.TableElement.EnsureRowVisible((GridViewHierarchyRowInfo)(this.radGridView1.CurrentRow).Parent);
                tableElement.ScrollToRow(this.radGridView1.CurrentRow);
                tableElement.EnsureRowVisible(this.radGridView1.CurrentRow);
            }
        }
    }
     
    GridTableElement tableElement = null;
     
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridDetailViewCellElement cell = e.CellElement as GridDetailViewCellElement;
        if (cell != null)
        {
            tableElement = cell.TableElement;
        }
     
        GridSearchCellElement searchCell = e.CellElement as GridSearchCellElement;
        if (searchCell != null)
        {
            searchCell.FindNextButton.MouseDown -= FindNextButton_MouseDown;
            searchCell.FindNextButton.MouseDown += FindNextButton_MouseDown;
            searchCell.FindPreviousButton.MouseDown -= FindPreviousButton_MouseDown;
            searchCell.FindPreviousButton.MouseDown += FindPreviousButton_MouseDown;
        }
    }
     
    private void FindPreviousButton_MouseDown(object sender, MouseEventArgs e)
    {
        this.radGridView1.Tag = "search";
    }
     
    private void FindNextButton_MouseDown(object sender, MouseEventArgs e)
    {
        this.radGridView1.Tag = "search";
    }

    As to the performance problem, I was unable to reproduce it on my end. However, after a few tests, it seems that scrolling to the parent row is enough for the scroll bar to move correctly and it is not necessary to scroll to the specific child row. Feel free to remove this code line from the workaround.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  9. Ingo
    Ingo avatar
    15 posts
    Member since:
    Apr 2016

    Posted 14 Apr Link to this post

    Hello,

    Thank You for Your answer!

    This solution works very well!

    Regards,

    Ingo

Back to Top
UI for WinForms is Visual Studio 2017 Ready