How to get the RadCheckBox element in a RadGridView and toggle the checkbox

1 Answer 79 Views
Buttons, RadioButton, CheckBox, etc GridView
Suhaib
Top achievements
Rank 1
Iron
Suhaib asked on 02 Oct 2024, 03:45 PM | edited on 02 Oct 2024, 03:56 PM

I have a RadGridView that has its first column(named "Visible") as a CheckBox cell in every row.

I have another CheckBox that toggles all the CheckBoxes in the GridView. In this CheckBox's ToggleStateChanged handler, I am trying to get the checkbox element in the GridView row and toggle its state.

This is what I am trying at the moment:

foreach(var myGridRow in curveGridView.Rows)
{
    ((GridViewCheckBoxColumn)myGridRow.Cells["Visible"].ColumnInfo).Checked = Telerik.WinControls.Enumerations.ToggleState.On;
}

However, I am unable to get the RadCheckBox element in the GridView Row and I cannot toggle the checkbox in the row.

Any help would be greatly appreciated.

Suhaib
Top achievements
Rank 1
Iron
commented on 02 Oct 2024, 04:25 PM

one thing to note for this issue is that the checkbox to toggle all other checkboxes in the gridview is outside the gridview.

i.e. I have a groupbox. The groupbox contains the CheckBox and the GridView. This groupbox contains the CheckBox to toggle all other GridView checkboxes. Hope this helps understand better.

1 Answer, 1 is accepted

Sort by
1
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 07 Oct 2024, 11:29 AM

Hello, Suhaib,

According to the provided information, it seems that you have a GridViewCheckBoxColumn added to the grid which is named "Visible". If I understand correctly, you would like to mark all the checkboxes as checked outside the grid. To do so, you should set the Value property of the respective GridViewCellInfo.

Cells can be accessed by column index or name. More information on this topic is available here: Accessing Cells - WinForms GridView Control - Telerik UI for WinForms

Here is a sample code snippet of how to set the toggle state on for the checkboxes in grid, for example when clicking a button:

private void radButton2_Click(object sender, EventArgs e)
{
    //set Value
    foreach (GridViewDataRowInfo row in this.radGridView1.Rows)
    {
        row.Cells["Visible"].Value = true;
    }
}

I hope this information is useful. If you have any other questions do not hesitate to contact me.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Buttons, RadioButton, CheckBox, etc GridView
Asked by
Suhaib
Top achievements
Rank 1
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or