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:


     

    <FONT color=#0000ff size=2><FONT color=#0000ff size=2>

    Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> fpConditions_MouseMove(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Object</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Windows.Forms.MouseEventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> fpConditions.MouseMove


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> InCell </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.Model.CellRange


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> RVI </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> CVI </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer

    </FONT></FONT><FONT size=2>

    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


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT>


    <FONT color=#0000ff size=2><FONT color=#0000ff size=2></FONT></FONT> 


    <FONT color=#0000ff size=2><FONT color=#0000ff size=2>I suspect this has something to do with knowing what viewport you're on??</FONT></FONT>


    <FONT color=#0000ff size=2><FONT color=#0000ff size=2>Oh this is an older version - 2.0.6</FONT></FONT>


    <FONT color=#0000ff size=2><FONT color=#0000ff size=2>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.</FONT></FONT>


    <FONT color=#0000ff>Or does the hierarchical view do that?</FONT>


    <FONT color=#0000ff></FONT> 


    <FONT color=#0000ff>Thanks</FONT>


    <FONT color=#0000ff><FONT size=2><FONT size=2> 

    </FONT></FONT></FONT>
  • 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