How to pass mousewheel event to parent sheet?

Posted by: klausr on 8 September 2017, 1:48 pm EST

  • Posted 8 September 2017, 1:48 pm EST

    Hello!


    I have a two level hierarchical dataset which i bind to a sheet. When a child sheet is visible the behaviour of the mousewheel is not the way I want it.
    If I start mousewheeling with the cursor over the parent sheet, the parent sheet scrolls as intended. But when the child sheet then is scrolled to a position where the cursor is over the child sheet, the scrolling stops since the child sheet takes over the scrolling (And all the rows of the child sheet are visible => no scrolling). 
    I want to be able to scroll the entire spread, parent sheet AND child sheets as one, regardless of which sheet the cursor is over.


    Using info in another forum post I managed to figure out if the cursor is over a child sheet or not:


    Private Sub ssData_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ssData.MouseWheel
      For Each sv As FarPoint.Win.Spread.SpreadView In ssData.GetRootWorkbook.GetChildWorkbooks
        Dim cr As FarPoint.Win.Spread.Model.CellRange = sv.GetCellFromPixel(e.X, e.Y)
        If cr.Column <> -1 Then 'If cr.column = -1 we're in the parent sheet.                      
          'Pass the MouseWheel event to the parent sheet. How???
        End If
      Next
    End Sub


    How do I make the parent sheet scroll instead of the child sheet?


    I'm using Spread for winforms, version 2.5.2013.2005


    The behaviour is reproducable in the HierarchyVB sample project.


    Regards


    Niklas

  • Replied 8 September 2017, 1:48 pm EST

    Helllo Niklas,


    Regarding your query, the already discussed information at the following location may help you;


    http://www.clubfarpoint.com/Forums/forums/thread/4910.aspx

    http://www.clubfarpoint.com/Forums/forums/thread/18033.aspx


    Thanks

  • Replied 8 September 2017, 1:48 pm EST

    Hello Suresh, and thank you for answering.


    (I've been out of town for a week, thus my silence)


    I read both these two threads before my initial posting. My impression was that the first thread related to a bug in an older version of spread (This bug, 13625, was fixed in version 1.0.3) before turning into a scrollbar inheritage discussion.


    The second one refers to horizontal scrolling, whereas my problem regards vertical scrolling. However, I stole the code in that thread in order to make my horizontal scrolling work better.


    Is it impossible to force the parent sheet to scroll even though the cursor is over a sub sheet? Please note that I use the terms sheet and view interchangeably as I haven't understood these concepts entirely.


    regards Niklas


     


     


  • Replied 8 September 2017, 1:48 pm EST

    Niklas,


    There is not a way to send the mouse to the parent SpreadView, but you could programatically move the SpreadViews the way you want. Here is some code I wrote to implement this.


    Private Sub FpSpread1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FpSpread1.MouseWheel


    For Each sv As FarPoint.Win.Spread.SpreadView In FpSpread1.GetRootWorkbook.GetChildWorkbooks


    Dim cr As FarPoint.Win.Spread.Model.CellRange = sv.GetCellFromPixel(e.X, e.Y)


    If cr.Column <> -1 Then 'If cr.column = -1 we're in the parent sheet.


    If e.Delta < 0 Then


    sv.SetViewportTopRow(0, sv.GetViewportTopRow(0) - 1)


    FpSpread1.SetViewportTopRow(0, FpSpread1.GetViewportTopRow(0) + 1)


    Else


    sv.SetViewportTopRow(0, sv.GetViewportTopRow(0) + 1)


    FpSpread1.SetViewportTopRow(0, FpSpread1.GetViewportTopRow(0) - 1)


    End If


    End If


    Next


    End Sub

  • Replied 8 September 2017, 1:48 pm EST

    how to write above code in c#
  • Marked as Answer

    Replied 8 September 2017, 1:48 pm EST

    Hello,

    Here is the C# code for the same :-

     void fpSpread1_MouseWheel(object sender, MouseEventArgs e)
    {
    foreach (FarPoint.Win.Spread.SpreadView sv in fpSpread1.GetRootWorkbook().GetChildWorkbooks())
    {
    FarPoint.Win.Spread.Model.CellRange cr = sv.GetCellFromPixel(e.X, e.Y);
    if ((cr.Column != -1))
    {
    if ((cr.Column == -1))
    {
    if (e.Delta < 0) ;
    sv.SetViewportTopRow(0, sv.GetViewportTopRow(0), 1);
    fpSpread1.SetViewportTopRow(0, (fpSpread1.GetViewportTopRow(0) + 1));
    }
    else
    {
    sv.SetViewportTopRow(0, (sv.GetViewportTopRow(0) + 1));
    fpSpread1.SetViewportTopRow(0, fpSpread1.GetViewportTopRow(0), 1);
    }

    }

    }
    }
    }

    Hope it helps.

    Thanks,
    Reeva
Need extra support?

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

Learn More

Forum Channels