RadSpreadsheet's vertical scrollbar is paging down by a single row at a time

3 posts, 1 answers
  1. Sandra
    Sandra avatar
    2 posts
    Member since:
    Aug 2014

    Posted 09 Feb 2015 Link to this post

    I've been trying out the RadSpreadsheet control in a small test application and am seeing some odd scrolling behavior, even within the provided samples.  (I'm using the 2014 Q3 version:  2014.3.1202.45.)

    When there are enough rows in the viewable area to make paging up or down possible (for example, the viewport shows 20 rows and the spreadsheet holds 100 rows), clicking on the scrollbar background only moves the contents up or down by a single row.

    I've attached an event handler to the sheet's ScrollBarsProvider.VerticalScrollBar.Scroll event, and I'm observing that the ScrollEventType is indeed LargeIncrement as expected, and the eventArgs.NewValue contents appear to be an expected large value.... however, the position within the sheet only moves by a single row.  This occurs within unmodified projects within the Telerik's xaml-sdk repository found on GitHub: https://github.com/telerik/xaml-sdk

    What is going on with the scrolling?  What can I do to make the vertical scrollbar behave as expected?

    (Also, I just noticed the horizontal scrollbar is behaving in the same way - only scrolling by a single column at a time.)
  2. Answer
    Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 10 Feb 2015 Link to this post

    Hi Sandra,

    Internally the RadSpreadsheet handles the SmallIncrement and LargeIncrement both in the same way. This is the reason why it scrolls just one cell at a time.

    I have prepared a sample code which you could use to workaround the behavior of the RadSpreadsheet. It handles only for vertical scrolling and the LargeIncrement, but you could easily modify it so it work for LargeDecrement and horizontal scrolling too:
    private double verticalOffset;
     
    public MainWindow()
    {
        InitializeComponent();
     
        this.Loaded += this.MainWindow_Loaded;
        this.Unloaded += this.MainWindow_Unloaded;
    }
     
    private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.radSpreadsheet.VerticalScrollBar.Scroll += this.VerticalScrollBar_Scroll;
        this.verticalOffset = this.radSpreadsheet.VerticalScrollBar.Value;
    }
     
    private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
    {
        this.radSpreadsheet.VerticalScrollBar.Scroll -= this.VerticalScrollBar_Scroll;
    }
     
    private void VerticalScrollBar_Scroll(object sender, ScrollEventArgs e)
    {
        Worksheet worksheet = this.radSpreadsheet.ActiveWorksheet;
        ViewportPane viewportPane = this.radSpreadsheet.ActiveWorksheetEditor.SheetViewport[ViewportPaneType.Scrollable];
        CellRange scrollablePaneVisibleRange = viewportPane.VisibleRange;
        int topRowIndex = scrollablePaneVisibleRange.FromIndex.RowIndex;
        double currentOffset = e.NewValue;
        double delta = Math.Abs(currentOffset - this.verticalOffset);
     
        int newRowIndex = topRowIndex;
        if (e.ScrollEventType == ScrollEventType.LargeIncrement)
        {
            double rowHeights = viewportPane.Rect.Top;
            while (rowHeights < delta)
            {
                rowHeights += worksheet.Rows[newRowIndex].GetHeight().Value.Value;
                newRowIndex++;
            }
     
            this.radSpreadsheet.SetVerticalOffset(rowHeights);
        }
    }

    I have created a public item for your request in our feedback portal, where you can vote and subscribe in order to receive updates on the matter.

    Regards,
    Nikolay Demirev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sandra
    Sandra avatar
    2 posts
    Member since:
    Aug 2014

    Posted 10 Feb 2015 in reply to Nikolay Demirev Link to this post

    Nikolay - thanks for the response!  I've adapted the code to work in my test application, and it solves the problem.

    A couple of comments (if anyone else sees this behavior): - I had to attach/detach the scroll event handlers in the RadSpreadsheet object's Loaded and Unloaded events, because in my case the RadSpreadsheet is initially hidden - the VerticalScrollBar / HorizontalScrollBar properties are null when the window is loaded.

    Also modified the workaround code to handle scrolling up as well as down (check for ScrollEventType.LargeDecrement also).
Back to Top