programmatically scrolling the scrollbar

Posted by: pontius on 8 September 2017, 3:03 pm EST

  • Posted 8 September 2017, 3:03 pm EST

    Hi,

    how can I programmatically scroll the scrollbar in order to see a row in the visible area?

    Let's say I have 200 rows and 20 of them fit into the visible area.

    Now I want the row #73 be shown in a way that I see rows beginning from 63 and ending with 83.

    Regards,
    Pontius

  • Replied 8 September 2017, 3:03 pm EST

    Pontius,

    To scroll row labeled 63 to the top of the viewport, you could use the following code...

    <blockquote>

    fpSpread1.SetViewportTopRow(0, 62);

    </blockquote>

    or...

    <blockquote>

    fpSpread1.ShowRow(0, 62, VerticalPosition.Top);

    </blockquote>


    To scroll row labeled 73 to the middle of the viewport, you could use the following code...

    <blockquote>

    fpSpread1.ShowRow(0, 72, VerticalPosition.Center);

    </blockquote>
  • Replied 8 September 2017, 3:03 pm EST

    bobbyo,

    thanks.

    With the ShowRow method I have to use the VerticalPosition enum which allows Top, Center, Bottom, Nearest.

    However, when the row is already shown I do not want to touch the ScrollBar at all.
    I mean I do not want to let the row jump from its current position to the e.g. VerticalPosition.Center position.

    In order to find out if the row is shown already I tried:
    int top = GetViewportTopRow(0)
    int bot = GetViewportBottomRow(0)

    However these methods always provide the same values for top and bot.
    So I don't know how to find out if the row is shown already.

    Regards,
    Pontius

  • Replied 8 September 2017, 3:03 pm EST

    Pontius,

    When I tested the FpSpread's GetViewportTopRow and GetViewportBottomRow methods, I did not have any problems. For example, the following code would only scroll if the desired row was not visible.

    <blockquote>

    int newRow = 72;
    int topRow = fpSpread1.GetViewportTopRow(0);
    int bottomRow = fpSpread1.GetViewportBottomRow(0);
    if (newRow < topRow || bottomRow < newRow)
    {
        fpSpread1.ShowRow(0, newRow, VerticalPosition.Center);
    }

    </blockquote>

    If you could provide a sample application (or code) that demostrates the problem you are encountering with the GetViewportTopRow and GetViewportBottomRow methods then we could debug the issue.

    The VerticalPosition's Nearest option will only scroll when the desired row is not visible. For example, the following code will scroll the sheet just enough to make the desired cell visible.

    <blockquote>

    int newRow = 72;
    fpSpread1.ShowRow(0, newRow, VerticalPosition.Nearest);

    </blockquote>
  • Replied 8 September 2017, 3:03 pm EST

    Sorry, my bad.

    Previous to GetViewportTopRow some other code segment deleted all the items and reconstructed them. So the scrollbar was always at the top.

    Thanks and regards,
    Pontius

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels