GridView: CheckBox visible and enabled conditionally.

2 posts, 0 answers
  1. Eusebio
    Eusebio avatar
    44 posts
    Member since:
    Aug 2020

    Posted 12 Nov 2020 Link to this post

    Hi,

     

    In some rows of the grid I need the CHECKBOX to be visible and enabled. How do I do that?

    I attach an image.

     

    Best regards.

  2. Nadya
    Admin
    Nadya avatar
    459 posts

    Posted 12 Nov 2020 Link to this post

    Hello, Eusebio,

    I suppose that you are using GridViewCheckBoxColumn in the grid. By default, the checkboxes are always visible. If you want to have checkboxes visible only for specific rows, you should handle the CellFormatting event and manage RadCheckBoxEditorElement's Visibility property:

    private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridCheckBoxCellElement cell = e.CellElement as GridCheckBoxCellElement;
        if (cell != null)
        {
            RadCheckBoxEditorElement editorElement = (cell.Editor as RadCheckBoxEditor).EditorElement as RadCheckBoxEditorElement;
            if (e.RowIndex == 0 || e.RowIndex == 1)
            {
                editorElement.Visibility = ElementVisibility.Visible;
            }
            else
            {
                editorElement.Visibility = ElementVisibility.Hidden;
            }
        }
    }
    

    I hope this helps. Should you have further questions please let me know.

    Regards,
    Nadya
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top