Set active cell right clink in child view

Posted by: patrik on 1 April 2019, 2:24 pm EST

    • Post Options:
    • Link

    Posted 1 April 2019, 2:24 pm EST

    Hi

    I use drag and drop as below. it’s working perfect if I first click on the cell with left mouse button and then use right click for drag and drop.

    is it possible to set active cell with right click as below?

    
     Private Sub FpSpread3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FpSpread3.MouseDown
            If e.Button = MouseButtons.Right Then
                FpSpread3.DoDragDrop(Select_a, DragDropEffects.Copy Or DragDropEffects.Move)
            End If
        End Sub
    
    Private Sub FpSpread3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FpSpread3.MouseUp
            Try
                iRow = FpSpread3.ActiveSheet.ActiveRowIndex
                Select_a = FpSpread3.GetRootWorkbook.GetActiveWorkbook.Sheets(0).ActiveCell.Text
            Catch ex As Exception
                'MessageBox.Show("You didn't make a selection!!")
                Return
            End Try
        End Sub
    
    
    
  • Posted 2 April 2019, 7:26 am EST

    Hello,

    It should work to handle the CellClick event to check whether the right button was clicked in the cell and then set the active cell with SetActiveCell() as shown below:-

      Private Sub FpSpread1_CellClick(sender As Object, e As CellClickEventArgs) Handles FpSpread1.CellClick
            If e.Button = MouseButtons.Right Then
                FpSpread1_Sheet1.SetActiveCell(e.Row, e.Column)
    
            End If
        End Sub
    

    Hope it helps.

    Thanks,

    Reeva

  • Posted 2 April 2019, 9:00 am EST

    Problem is that this is not working when I use Mouse Down and Up.

    Is there someway to do this inside Mouse Down?

  • Posted 3 April 2019, 3:46 am EST

    Hello,

    Use this code to set active cell on mouse right click event:-

     
        Private Sub FpSpread1_MouseDown(sender As Object, e As MouseEventArgs) Handles FpSpread1.MouseDown
            If e.Button = MouseButtons.Right Then
                Dim range As FarPoint.Win.Spread.Model.CellRange = FpSpread1.GetCellFromPixel(0, 0, e.X, e.Y)
                FpSpread1_Sheet1.SetActiveCell(range.Row, range.Column)
            End If
        End Sub
    
    

    Hope it helps.

    Thanks,

    Reeva

  • Posted 4 April 2019, 10:38 am EST

    Thanks for your answer

    this is not working. I have a child view.

    to read text on active cell I use:

    FpSpread3.GetRootWorkbook.GetActiveWorkbook.Sheets(0).ActiveCell.Text

  • Posted 4 April 2019, 11:27 am EST

    I make it’s working this way, is this the best way or can it’s be more simple?

    Dim sv As FarPoint.Win.Spread.SpreadView

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

    sv = GetSpreadView(FpSpread3.GetRootWorkbook(), e.X, e.Y)

    cr = sv.GetCellFromPixel(0, 0, e.X, e.Y)

            sv.Sheets(0).SetActiveCell(cr.Row, cr.Column)
            Select_a = FpSpread3.GetRootWorkbook.GetActiveWorkbook.Sheets(0).Cells(cr.Row, cr.Column).Text
    

    Private Function GetSpreadView(ByVal sv As FarPoint.Win.Spread.SpreadView, ByVal x As Integer, ByVal y As Integer) As FarPoint.Win.Spread.SpreadView

    Try

    Dim r As Rectangle = sv.Bounds

    Dim c As FarPoint.Win.Spread.SpreadView

    Dim ret As FarPoint.Win.Spread.SpreadView

    If Not r.Contains(x, y) Then Return Nothing

    Dim al As ArrayList = sv.GetChildWorkbooks()

    For Each c In al

    ret = GetSpreadView(c, x, y)

    If Not ret Is Nothing Then Return ret

    Next

    Return sv

    Catch Ex As Exception

    Throw Ex

    End Try

    End Function

  • Posted 4 April 2019, 11:40 pm EST

    Hello,

    This is the correct way of doing it in case of child view.

    Thanks,

    Reeva

Need extra support?

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

Learn More

Forum Channels