Hide checkbox in RadGridView

9 posts, 1 answers
  1. Andy
    Andy avatar
    25 posts
    Member since:
    Jan 2011

    Posted 27 Jan 2011 Link to this post

    Hi,

    I have a RadGridView that has a checkbox column. When adding a new row (using AddNew method, if that matters), depending on some condition, I want to hide the checkbox of that row. It seemed simple enough, but I couldn't figure it out. Am I missing something obvious?

    Please help. Thanks.

    Andy
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Jan 2011 Link to this post

    Hello Andy,

    You can hide the checkbox using the cell formatting event. Please have a look at my answer in this forum post which should help you to do this. If yo uneed further help though please let me know
    Thanks
    Richard
  3. Andy
    Andy avatar
    25 posts
    Member since:
    Jan 2011

    Posted 28 Jan 2011 Link to this post

    Hi Richard,
    That worked, but it introduced an unwanted effect: the top border of the collapsed cell disappeared. Please see the attached image. Is there a workaround to this problem?

    Thanks,
    Andy
  4. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Jan 2011 Link to this post

    Hi Andy,

    Yes, there is a better solution actually than the one I originally proposed.

    It's just to make the checkmark itself collpased rather than the whole cell.

    Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
        If TypeOf e.CellElement Is GridCheckBoxCellElement Then ' If its a Checkbox cell 
            If e.CellElement.RowInfo.Cells("Id").Value IsNot Nothing Then ' and the Id column (for exmaple) is not null 
                If Convert.ToInt32(e.CellElement.RowInfo.Cells("Id").Value) = 1 Then ' If the Id is 1 
                    CType(e.CellElement.Children(0), RadCheckBoxEditorElement).Checkmark.Visibility = ElementVisibility.Collapsed
                End If
            End If
        End If
    End Sub

    Let me know if that helps
    Richard
  5. Andy
    Andy avatar
    25 posts
    Member since:
    Jan 2011

    Posted 28 Jan 2011 Link to this post

    Hi Richard,

    Your new method works well. Thank you for the quick response.

    Andy
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 28 Jan 2011 Link to this post

    No problem Andy. Glad I could help
    All the best
    Richard
  7. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 02 Feb 2011 Link to this post

    Hello,

    Richard's solution is fine. I would like only to point out how to use the API of the GridCheckBoxCellElement to achieve this result:
    private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridCheckBoxCellElement cell = e.CellElement as GridCheckBoxCellElement;
        if (cell != null)
        {
            RadCheckBoxEditor editor = cell.Editor as RadCheckBoxEditor;
            editor.EditorElement.Visibility = ElementVisibility.Collapsed;
        }
    }

    Best regards,
    Alexander
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  8. Michael
    Michael avatar
    47 posts
    Member since:
    Oct 2010

    Posted 28 Apr 2017 in reply to Alexander Link to this post

    This solution works great.  I've been able to do the same with a GridCommandCellElement, but I can't figure out how to hide a GridDataCellElement.  I have a GridViewDecimalColumn and GridViewComboboxColumn in my grid and I want to show or hide the content based on some criteria.  Cell.Editor seem to be a null in both cases.
  9. Hristo
    Admin
    Hristo avatar
    1520 posts

    Posted 28 Apr 2017 Link to this post

    Hello Michael,

    Thank you for writing.

    The Editor property is specific to the GridCheckBoxCellElement. For other data cells, you can still handle the CellFormatting event and set a certain property to change the visual appearance of the cell. Because of the virtualization of the control, please do not forget to add an else clause and reset the properties. Additional information is available here: Formatting Cells.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top