Two spread controls with common scrollbar

Posted by: lakki on 8 September 2017, 1:18 pm EST

  • Posted 8 September 2017, 1:18 pm EST

    Hello,


    In my application, I place 2 spread side by side. I want to have common vertical n horizontal scrollbars.


    I looked into viewports, but that doesnot suit my requirement since I want to have spreads with different data. How can I do this?


    Thank you,


    Lakki

  • Replied 8 September 2017, 1:18 pm EST

    Lakki -

     There is not a way to share scrollbars but you can scroll one spread based on the scrolling of another.  Use the LeftChange and TopChange events of the spread you are scrolling and then in that event use the SetViewportTopRow and SetViewportLeftColumn methods of the other spread to scroll the other spread.
     

  • Replied 8 September 2017, 1:18 pm EST

    Hello,


    As u said, I used TopChange and LeftChange events to scroll, bt the FpSpread2 doesnot scroll till the first 10rows of FpSpread1 are scrolled. After that FpSpread2 scrolls but always the row shown at top is 10 less than that shown at the top of Fpspread2.


    Here is the code:


     Private Sub FpSpread1_TopChange(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.TopChangeEventArgs) Handles FpSpread1.TopChange
            FpSpread2.ShowCell(0, 0, e.NewTop, 0, FarPoint.Win.Spread.VerticalPosition.Center, FarPoint.Win.Spread.HorizontalPosition.Left)
            Console.WriteLine(e.NewTop)
        End Sub


    Private Sub FpSpread1_LeftChange(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.LeftChangeEventArgs) Handles FpSpread1.LeftChange
            FpSpread2.ShowCell(0, 0, 0, e.NewLeft, FarPoint.Win.Spread.VerticalPosition.Center, FarPoint.Win.Spread.HorizontalPosition.Left)
    End Sub


    And this is the version I use SPREAD for .NET 3.0J Windows Forms Edition release Version 3.0.2006.2005


    Thank you,


    Lakki


     


     

  • Replied 8 September 2017, 1:18 pm EST

    You are using the ShowCell method.  This is not correct.  Use the SetViewportTopRow and SetViewportLeftColumn.
  • Replied 8 September 2017, 1:18 pm EST

    Hello,


    I used SetViewportTopRow, SetViewportLeftColumn. Its working, but bit strange at times.


    I have attached the code below:


    Public Class Form1


        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


            HScrollBar1.Maximum = FpSpread1.ActiveSheet.Columns.Count
            HScrollBar1.LargeChange = 5             'To move 5 columns at once
            HScrollBar1.SmallChange = 1             'To move 1 column at a time


        End Sub


        Private Sub FpSpread2_TopChange(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.TopChangeEventArgs) Handles FpSpread2.TopChange
            FpSpread1.SetViewportTopRow(e.RowViewportIndex, e.NewTop)
        End Sub


        Private Sub FpSpread2_LeftChange(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.LeftChangeEventArgs) Handles FpSpread2.LeftChange
            FpSpread1.SetViewportLeftColumn(e.ColumnViewportIndex, e.NewLeft)
        End Sub


        Private Sub FpSpread1_TopChange(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.TopChangeEventArgs) Handles FpSpread1.TopChange
            FpSpread2.SetViewportTopRow(e.RowViewportIndex, e.NewTop)
        End Sub


        Private Sub FpSpread1_LeftChange(ByVal sender As System.Object, ByVal e As FarPoint.Win.Spread.LeftChangeEventArgs) Handles FpSpread1.LeftChange
            FpSpread2.SetViewportLeftColumn(e.ColumnViewportIndex, e.NewLeft)
            HScrollBar1.Value = e.NewLeft
        End Sub


        Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll


            FpSpread2.SetViewportLeftColumn(FpSpread2.GetViewportLeftColumn(e.OldValue), e.NewValue)


        End Sub


    End Class


    I place 2 spreadcontrols on a windows form. I setVerticalScrollBarPolicy and HorizontalScrollBarPolicy of FpSpread1 as "Never" and only HorizontalScrollBarPolicy of FpSpread2 as "Never". I use .net for windows form control "HScrollBar" as a common scroll bar. Vertical scroll is working fine. When I scroll towards right by clicking HScrollBar it scrolls neatly. But, when I scroll towards left, it scrolls till the first+1 column bt doesnt scroll till the first column. What would be the problem?


    Thank you,


    Lakki

  • Replied 8 September 2017, 1:18 pm EST

    Lakki,


    Is the first column hidden or frozen in the first Spread control? If not, and you are trying to use the horizonal scrollbar control to scroll the second Spread, the issue is in your code. The SetViewportLeftColumn method takes the column viewport index as the first parameter. If you do not have any extra column viewports, then this should always be 0.

Need extra support?

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

Learn More

Forum Channels