Description:
Your GridMainDemo project (the CustomDraw module) shows how to paint expand buttons using images. Is there another way to paint these buttons?
Answer:
It is possible to paint expand buttons using exactly the same methods the XtraGrid uses itself. Here is some sample code showing how this can be implemented:
C#private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e) {
DevExpress.XtraGrid.Views.Grid.GridView view;
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo ee;
DevExpress.Utils.Drawing.OpenCloseButtonInfoArgs ocb;
DevExpress.XtraGrid.Drawing.GridGroupRowPainter painter;
view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
ee = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo;
ocb = new DevExpress.Utils.Drawing.OpenCloseButtonInfoArgs(e.Cache, ee.ButtonBounds,
ee.GroupExpanded, ee.AppearanceGroupButton, DevExpress.Utils.Drawing.ObjectState.Normal);
if(!ee.ButtonBounds.IsEmpty) {
painter = e.Painter as DevExpress.XtraGrid.Drawing.GridGroupRowPainter;
painter.ElementsPainter.OpenCloseButton.DrawObject(ocb);
}
e.Handled = true;
}
Visual BasicPrivate Sub GridView1_CustomDrawGroupRow(ByVal sender As Object, ByVal e As _
DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs) Handles GridView1.CustomDrawGroupRow
Dim view As DevExpress.XtraGrid.Views.Grid.GridView
Dim ee As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo
Dim ocb As DevExpress.Utils.Drawing.OpenCloseButtonInfoArgs
Dim painter As DevExpress.XtraGrid.Drawing.GridGroupRowPainter
view = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
ee = CType(e.Info, DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo)
ocb = New DevExpress.Utils.Drawing.OpenCloseButtonInfoArgs(e.Cache, ee.ButtonBounds, _
ee.GroupExpanded, ee.AppearanceGroupButton, DevExpress.Utils.Drawing.ObjectState.Normal)
If Not ee.ButtonBounds.IsEmpty Then
painter = CType(e.Painter, DevExpress.XtraGrid.Drawing.GridGroupRowPainter)
painter.ElementsPainter.OpenCloseButton.DrawObject(ocb)
End If
e.Handled = True
End Sub
See Also:
How to align summary values displayed in a group row to the corresponding columns