KB Article A1487
Visible to All Users

How to hide a check box in a grid cell

Description:
One of my grid column has the CheckEdit repository item. I need to dynamically hide check boxes in some cells. What is the easiest solution?

Answer:
Applies to:
XtraGrid, XtraTreeList, XtraVerticalGrid
Usually, the CustomRowCellEdit event is used to specify in-place editors on a cell by cell basis. To hide an editor, you should use the RepositoryItemButtonEdit editor:

C#
RepositoryItemButtonEdit emptyEditor; private void Form1_Load(object sender, System.EventArgs e) { emptyEditor = new RepositoryItemButtonEdit(); emptyEditor.Buttons.Clear(); emptyEditor.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor; gridControl1.RepositoryItems.Add(emptyEditor); new DevExpress.XtraGrid.Design.XViewsPrinting(gridControl1); } bool NeedToHideDiscontinuedCheckbox(GridView view, int row) { return true; // your code here.... } private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) { if(e.Column.FieldName == "Discontinued" && NeedToHideDiscontinuedCheckbox(sender as GridView, e.RowHandle)) e.RepositoryItem = emptyEditor; }
Visual Basic
Private emptyEditor As RepositoryItemButtonEdit Private Sub Form1_Load(sender As Object, e As System.EventArgs) emptyEditor = New RepositoryItemButtonEdit() emptyEditor.Buttons.Clear() emptyEditor.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor gridControl1.RepositoryItems.Add(emptyEditor) New DevExpress.XtraGrid.Design.XViewsPrinting(gridControl1) End Sub Private Function NeedToHideDiscontinuedCheckbox(view As GridView, row As Integer) As Boolean Return True ' your code here.... End Function Private Sub gridView1_CustomRowCellEdit(sender As Object, e As CustomRowCellEditEventArgs) If e.Column.FieldName = "Discontinued" AndAlso NeedToHideDiscontinuedCheckbox(TryCast(sender, GridView), e.RowHandle) Then e.RepositoryItem = emptyEditor End If End Sub

See also:
A249

Comments (2)

    Dear,
    i need to hide the checkbox in a master / detail view, inside the detail view. Your szenario ist not working , please advise.
    Tx a lot

    DevExpress Support Team 9 years ago

      Hello,

      To process your recent post more efficiently, I created a separate ticket on your behalf: T332792: How to hide a check box in a detail View column. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.