Devexpress XtraGrid's multiple rows into footer
This article describes a way to insert multiple rows into a Devexpres WinForm XtraGrid footer. First step is to add a XtraGrid into your WinForm and set to true it’s ShowFooter property.
Once the footer it’s visible you can add cells into it using the GUI or programmatically.
Code for adding cells into footer look like this:
grid.firstcollumn.SummaryItem.Assign( new GridSummaryItem(DevExpress.Data.SummaryItemType.None, "fieldName", "displayFormat"));
Devexpress XtraGrid provide an event (CustomDrawFooterCell) that go through every footer’s cell and allow to change it’s appearance. I used this event to add multiple cells on a single column.
private void gridView1_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
int iRowHeight = 25;
if(e.Column.Name.Equals("fieldName"))
{
for (int i = 0; i < 3; i++)
{
e.Info.Appearance.BackColor = Color.Transparent;
e.Info.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
e.Info.DisplayText = "displayedText";
Rectangle r = new Rectangle(e.Info.Bounds.Left, e.Info.Bounds.Top + (i * iRowHeight ), e.Info.Bounds.Width, e.Info.Bounds.Height);
e.Info.BackAppearance.DrawBackground(e.Cache, r);
e.Info.BackAppearance.DrawString(e.Cache, e.Info.DisplayText, r);
}
e.Handled = true;
}
}
Previous code paint 3 cells into specific column and display a text over them.


Tags: 



Leave a Reply