Hide checkboxes in a GridCheckBox in WinForms DataGrid (SfDataGrid) ?
In SfDataGrid GridCheckBoxColumn, checkbox will be displayed for all the cells by default. You can hide the checkbox for some specific cells in the GridCheckBoxColumn based on another column value in the same row by creating custom renderer for the checkbox column.
public Form1() { InitializeComponent(); this.sfDataGrid1.DataSource = new OrderInfoCollection().OrdersListDetails; this.sfDataGrid1.CellRenderers["CheckBox"] = new CustomCheckBoxCellRenderer(); } public class CustomCheckBoxCellRenderer : GridCheckBoxCellRenderer { protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) { if (column.GridColumn.MappingName == "IsClosed") { DataRowBase dataRow = (DataRowBase)column.GetType().GetProperty("DataRow", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(column); if ((dataRow.RowData as OrderInfo).Quantity > 50) paint.FillRectangle(new SolidBrush(style.BackColor), cellRect); else base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex); } } }
Conclusion
I hope you enjoyed learning about how to Hide checkboxes in a GridCheckBox in WinForms DataGrid (SfDataGrid).
You can refer to our WinForms DataGrid feature
tour page to know about its other groundbreaking feature
representations and documentation, and
how to quickly get started for configuration specifications. You can also
explore our
WinForms DataGrid
example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!