How to change the visibility of PreviewRowExpander in WinForms DataGrid?
WinForms DataGrid (SfDataGrid) does not provide the direct support to change the visibility of PreviewRowExpander. You can change the visibility of PreviewRowExpander by overriding OnRender method in PreviewRowExpanderCellRenderer.
//PreviewRowExpander
this.sfDataGrid.CellRenderers.Remove("PreviewRowExpander");
this.sfDataGrid.CellRenderers.Add("PreviewRowExpander", new PreviewRowExpanderCellRendererExt());
public class PreviewRowExpanderCellRendererExt : PreviewRowExpanderCellRenderer
{
private void PaintCellBackground(Graphics graphics, Rectangle cellRect, CellStyleInfo style, bool canApplyInterior)
{
if (canApplyInterior && style.HasInterior)
Syncfusion.WinForms.Core.BrushPainter.FillRectangle(graphics, cellRect, style.Interior);
else
{
Brush backColor = new SolidBrush(style.BackColor);
graphics.FillRectangle(backColor, cellRect);
Syncfusion.ComponentModel.DisposeHelper.Dispose(ref backColor);
}
}
protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex)
{
// To draw background for the Expander cell.
PaintCellBackground(paint, cellRect, style, true);
}
}

The following screenshot shows the changed visibility of PreviewRowExpander in WinForms DataGrid (SfDataGrid),
Take a moment to peruse the WinForms DataGrid – Preview Rows documentation, where you can find about Preview Rows with code examples.
Please refer this link to know about the essential features of WinForms DataGrid.
You can download the example from GitHub
Conclusion
I hoped you enjoyed learning on how to change the visibility of PreviewRowExpander in WinForms DataGrid.
You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations 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!
