Use shift-click to check/uncheck multiple checkboxes?

Posted by: ginacresse on 8 September 2017, 1:11 pm EST

  • Posted 8 September 2017, 1:11 pm EST

    Hello,


    I have a spread with "select" checkboxes in the first row.  I want the user to be able to check/uncheck multiple boxes by checking one box then shift-click another box and replicate the check/uncheck on all checkboxes in between and including the last box checked.  Is there a way to do that with Farpoint Spread?  I'm not sure how to capture the shift-click combination.


    Thanks

  • Replied 8 September 2017, 1:11 pm EST

    ginacresse -

    I can tell you how to get the shift-click combination.  In the MouseDown event of the spread check the following...

    If My.Computer.Keyboard.ShiftKeyDown Then

    End If

    However, I've been playing around with this and I do not see an easy way to accomplish your objective.  I'll continue to investigate it and let you know if I come up with a solution.
  • Replied 8 September 2017, 1:11 pm EST

    Hi Bob,


    I came up with this code, but I have one problem.  When I put a breakpoint and step through the for/next loop, it works perfectly and checks/unchecks all the boxes it should.  If I don't step through it, it consistenly leaves the last checkbox in the opposite state than it should.  It must be a timing issue, but I'm not sure how to resolve it.  Any ideas?


    Public Class Form1


    Dim SaveChkBoxRow As Short


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


    Dim CheckBox As New FarPoint.Win.Spread.CellType.CheckBoxCellType


    With Me.FpSpread1.ActiveSheet


    .Columns(0).CellType = CheckBox


    .Columns(0).HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center


    End With


    End Sub


    Private Sub FpSpread1_ButtonClicked(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles FpSpread1.ButtonClicked


    If Not My.Computer.Keyboard.ShiftKeyDown Then 'save the last checkbox row clicked by the user


    With Me.FpSpread1.ActiveSheet


    If .ActiveColumn.Index = 0 Then


    SaveChkBoxRow = .ActiveRow.Index


    End If


    End With


    End If


    End Sub


    Private Sub FpSpread1_CellClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles FpSpread1.CellClick


    Dim Counter As Short


    Dim Checked As Boolean


    If My.Computer.Keyboard.ShiftKeyDown Then


    With Me.FpSpread1.ActiveSheet


    Checked = .GetValue(SaveChkBoxRow, 0) 'get the checked status of the checkbox we last left


    If SaveChkBoxRow < e.Row Then


    For Counter = SaveChkBoxRow To e.Row


    .SetValue(Counter, 0, Checked)


    .SetText(Counter, 1, Checked)


    Next


    Else


    For Counter = SaveChkBoxRow To e.Row Step -1


    .SetValue(Counter, 0, Checked)


    .SetText(Counter, 1, Checked)


    Next


    End If


    End With


    End If


    End Sub


    End Class

  • Replied 8 September 2017, 1:11 pm EST

    Okay, I added code to keep the for/next loop from re-setting the currently selected row and it seems to work well now.  Not sure if it's the most elegent way to accomplish this, but it works.


    Public Class Form1


    Dim SaveChkBoxRow As Short


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


    Dim CheckBox As New FarPoint.Win.Spread.CellType.CheckBoxCellType


    With Me.FpSpread1.ActiveSheet


    .Columns(0).CellType = CheckBox


    .Columns(0).HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Center


    End With


    End Sub


    Private Sub FpSpread1_ButtonClicked(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EditorNotifyEventArgs) Handles FpSpread1.ButtonClicked


    If Not My.Computer.Keyboard.ShiftKeyDown Then 'save the last checkbox row clicked by the user


    With Me.FpSpread1.ActiveSheet


    If .ActiveColumn.Index = 0 Then


    SaveChkBoxRow = .ActiveRow.Index


    End If


    End With


    End If


    End Sub


    Private Sub FpSpread1_CellClick(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.CellClickEventArgs) Handles FpSpread1.CellClick


    Dim Counter As Short


    Dim Checked As Boolean


    If My.Computer.Keyboard.ShiftKeyDown Then


    With Me.FpSpread1.ActiveSheet


    Checked = .GetValue(SaveChkBoxRow, 0) 'get the checked status of the checkbox we last left


    If SaveChkBoxRow < e.Row Then


    For Counter = SaveChkBoxRow To e.Row


    If Counter <> e.Row Then 'don't re-set the currently selected row


    .SetValue(Counter, 0, Checked)


    End If


    Next


    Else


    For Counter = SaveChkBoxRow To e.Row Step -1


    If Counter <> e.Row Then 'don't re-set the currently selected row


    .SetValue(Counter, 0, Checked)


    End If


    Next


    End If


    End With


    End If


    End Sub


    End Class

Need extra support?

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

Learn More

Forum Channels