Determining the cell from X Y in a child view?

Posted by: scott-k-berger on 8 September 2017, 1:31 pm EST

  • Posted 8 September 2017, 1:31 pm EST

    So I get a valid return for the row and column when I'm on the parent column of a hierarchical grid.


    As soon as I move the cursor to a child column, GetCellFromPixel returns the -1 I cant find it thing.


     Here's the code I'm using:


     


    Private Sub fpConditions_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles fpConditions.MouseMove


    Dim InCell As FarPoint.Win.Spread.Model.CellRange


    Dim RVI As Integer


    Dim CVI As Integer


    RVI = fpConditions.GetRowViewportIndexFromY(e.Y)


    CVI = fpConditions.GetColumnViewportIndexFromX(e.X)


    InCell = fpConditions.GetCellFromPixel(RVI, CVI, e.X, e.Y)


    txtRowNumber.Text = InCell.Row.ToString


    txtColumnNumber.Text = InCell.Column.ToString


    End Sub


     


    I suspect this has something to do with knowing what viewport you're on??


    Oh this is an older version - 2.0.6


    Im having a hard time wrapping my head around what a viewport is. How can we have multiple ones on the same sheet if I didn't establish them.


    Or does the hierarchical view do that?


     


    Thanks


     

  • Replied 8 September 2017, 1:31 pm EST

    Try something like this instead...

    Private Sub FpSpread1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FpSpread1.MouseMove
    Dim cr As FarPoint.Win.Spread.Model.CellRange
    For Each sv As FarPoint.Win.Spread.SpreadView In FpSpread1.GetRootWorkbook.GetChildWorkbooks
    cr = sv.GetCellFromPixel(e.X, e.Y)
    TextBox1.Text = cr.Column
    Next
    End Sub

  • Replied 8 September 2017, 1:31 pm EST

    I was about to head down that kind of path.


     So that says that I have to try GetCellFromPixel in every child view till I find out if I'm in that view?


    Do I do that row by row, or does GetChildWorkBooks flatten the hierarchy so I see them all as one big array of views?


     

  • Replied 8 September 2017, 1:31 pm EST

    With the code I provided it will return -1 if you are in a parent but give you the row and column if you are in a child view.
  • Replied 8 September 2017, 1:31 pm EST

    Thanks that is working - of course there's always the next issue


    I was doing drag/drop - and the X,Y for the dragdrop event is not the same as the X,Y for the mousemove event, so I'm not able to pick up what row I'm in. Is there a reason for that?

  • Replied 8 September 2017, 1:31 pm EST

    Hello,


    The X,Y coordinates you are getting in the DragDrop event are in screen coordinates. You need to translate them to client coordinates to get the correct location for the GetCellFromPixel method.


    Dim pt as Point = FpSpread1.PointToClient(x,y)

Need extra support?

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

Learn More

Forum Channels