CheckBox column

Posted by: hpadmasola1 on 8 September 2017, 2:07 pm EST

  • Posted 8 September 2017, 2:07 pm EST

    Hi, 


    Iam loading my grid where the first column is a checkbox. By default, I have all the checkboxes in the Grid as checked when I load my grid.


    I want to have a button on my page when clicked it should make all checkboxes unchecked. And when I click it again, it should check them all.


    I tried using the following code in the button click event but it didnt work properly.


    If BtnCheckall.Text = "UnCheck All" Then
                FPspread1.ActiveSheet.Columns(0).DataField = 0
                BtnCheckall.Text = "Check All"
    Else
                FPspread1.ActiveSheet.Columns(0).DataField = 1
                BtnCheckall.Text = "UnCheck All"
    End If


    Any help is appreciated.


    Harish

  • Replied 8 September 2017, 2:07 pm EST

    Hello Harish,

    If you have a Column as CheckBoxCellType and you want to select/unselect all the CheckBoxes at once you may loop through the Cells and set their corresponding value to 1 for True(Checked) and 0 for False(Unchecked).Please have a look at the following code snippet where Column(2) is a CheckBoxCellType and we are using a ButtonClick Event to Check/Uncheck the Check Boxes,

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Me.Button1.Text = "Check All" Then
                For i As Integer = 0 To FpSpread1.ActiveSheet.RowCount - 1
                    FpSpread1.ActiveSheet.Cells(i, 2).Value = 1
                Next
                Me.Button1.Text = "UnCheck All"

            Else : Me.Button1.Text = "UnCheck All"
                For i As Integer = 0 To FpSpread1.ActiveSheet.RowCount - 1
                    FpSpread1.ActiveSheet.Cells(i, 2).Value = 0
                Next
                Me.Button1.Text = "Check All"
            End If
        End Sub

    I hope it will help you.

    Thanks,

     

Need extra support?

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

Learn More

Forum Channels