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?

    <FONT color=#0000ff size=2>

    Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Class</FONT><FONT size=2> Form1


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> SaveChkBoxRow </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> Form1_Load(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.Load


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> CheckBox </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> FarPoint.Win.Spread.CellType.CheckBoxCellType


    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.FpSpread1.ActiveSheet


    .Columns(0).CellType = CheckBox


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


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_ButtonClicked(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.EditorNotifyEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.ButtonClicked


    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Not</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>My</FONT><FONT size=2>.Computer.Keyboard.ShiftKeyDown </FONT><FONT color=#0000ff size=2>Then</FONT><FONT size=2> </FONT><FONT color=#008000 size=2>'save the last checkbox row clicked by the user

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.FpSpread1.ActiveSheet


    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> .ActiveColumn.Index = 0 </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    SaveChkBoxRow = .ActiveRow.Index


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_CellClick(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.CellClickEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.CellClick


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Counter </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Checked </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Boolean

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>My</FONT><FONT size=2>.Computer.Keyboard.ShiftKeyDown </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.FpSpread1.ActiveSheet


    Checked = .GetValue(SaveChkBoxRow, 0) </FONT><FONT color=#008000 size=2>'get the checked status of the checkbox we last left

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> SaveChkBoxRow < e.Row </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> Counter = SaveChkBoxRow </FONT><FONT color=#0000ff size=2>To</FONT><FONT size=2> e.Row


    .SetValue(Counter, 0, Checked)


    .SetText(Counter, 1, Checked)


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> Counter = SaveChkBoxRow </FONT><FONT color=#0000ff size=2>To</FONT><FONT size=2> e.Row </FONT><FONT color=#0000ff size=2>Step</FONT><FONT size=2> -1


    .SetValue(Counter, 0, Checked)


    .SetText(Counter, 1, Checked)


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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


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

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

    <FONT color=#0000ff size=2>

    Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Class</FONT><FONT size=2> Form1


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> SaveChkBoxRow </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> Form1_Load(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.Load


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> CheckBox </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>New</FONT><FONT size=2> FarPoint.Win.Spread.CellType.CheckBoxCellType


    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.FpSpread1.ActiveSheet


    .Columns(0).CellType = CheckBox


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


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_ButtonClicked(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.EditorNotifyEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.ButtonClicked


    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Not</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>My</FONT><FONT size=2>.Computer.Keyboard.ShiftKeyDown </FONT><FONT color=#0000ff size=2>Then</FONT><FONT size=2> </FONT><FONT color=#008000 size=2>'save the last checkbox row clicked by the user

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.FpSpread1.ActiveSheet


    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> .ActiveColumn.Index = 0 </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    SaveChkBoxRow = .ActiveRow.Index


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Private</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Sub</FONT><FONT size=2> FpSpread1_CellClick(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Object</FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> FarPoint.Win.Spread.CellClickEventArgs) </FONT><FONT color=#0000ff size=2>Handles</FONT><FONT size=2> FpSpread1.CellClick


    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Counter </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Short

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>Dim</FONT><FONT size=2> Checked </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Boolean

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>My</FONT><FONT size=2>.Computer.Keyboard.ShiftKeyDown </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>With</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Me</FONT><FONT size=2>.FpSpread1.ActiveSheet


    Checked = .GetValue(SaveChkBoxRow, 0) </FONT><FONT color=#008000 size=2>'get the checked status of the checkbox we last left

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> SaveChkBoxRow < e.Row </FONT><FONT color=#0000ff size=2>Then

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> Counter = SaveChkBoxRow </FONT><FONT color=#0000ff size=2>To</FONT><FONT size=2> e.Row


    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> Counter <> e.Row </FONT><FONT color=#0000ff size=2>Then</FONT><FONT size=2> </FONT><FONT color=#008000 size=2>'don't re-set the currently selected row

    </FONT><FONT size=2>

    .SetValue(Counter, 0, Checked)


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2>For</FONT><FONT size=2> Counter = SaveChkBoxRow </FONT><FONT color=#0000ff size=2>To</FONT><FONT size=2> e.Row </FONT><FONT color=#0000ff size=2>Step</FONT><FONT size=2> -1


    </FONT><FONT color=#0000ff size=2>If</FONT><FONT size=2> Counter <> e.Row </FONT><FONT color=#0000ff size=2>Then</FONT><FONT size=2> </FONT><FONT color=#008000 size=2>'don't re-set the currently selected row

    </FONT><FONT size=2>

    .SetValue(Counter, 0, Checked)


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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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

    </FONT><FONT size=2>

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


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

    </FONT>
Need extra support?

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

Learn More

Forum Channels