Description:
When using master detail view, some of my master rows do not have children. The grid shows a dimmed [+] symbol on these rows. I would like the grid not to show any symbol on these occasions.
Is it possible to customize master detail symbols?
Answer:
The XtraGrid does not provide an option to hide master-detail expand buttons for empty details. You can work around this limitation via the CustomDrawCell event. Here is the necessary code:
C#
private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) { GridView view = sender as GridView; if (e.Column.VisibleIndex == 0 && view.OptionsDetail.SmartDetailExpandButtonMode != DetailExpandButtonMode.AlwaysEnabled) { bool isMasterRowEmpty; if (view.OptionsDetail.SmartDetailExpandButtonMode == DetailExpandButtonMode.CheckAllDetails) { isMasterRowEmpty = true; for (int i = 0; i < view.GetRelationCount(e.RowHandle); i++) { if (!view.IsMasterRowEmptyEx(e.RowHandle, i)) { isMasterRowEmpty = false; break; } } } else isMasterRowEmpty = view.IsMasterRowEmpty(e.RowHandle); if (isMasterRowEmpty) (e.Cell as GridCellInfo).CellButtonRect = Rectangle.Empty; } }
See Also:
How to hide expand/collapse buttons for master rows without detail records
How to paint the master row's expand buttons within the CustomDrawCell event in exactly the same manner as the XtraGrid does