Custom Draw
- 3 minutes to read
The Custom Painting technology lets you customize appearances of individual elements to any extent you like.
Related API
The Pivot Grid offers you a set of events that can be handled to paint desired elements manually.
- PivotGridControl.CustomDrawCell
- Applies to: Cell
- PivotGridControl.CustomDrawEmptyArea
- Applies to: Empty Area
- PivotGridControl.CustomDrawFieldHeader
- Applies to: Field Header
- PivotGridControl.CustomDrawFieldHeaderArea
- Applies to: Header Area
- PivotGridControl.CustomDrawFieldValue
- Applies to: Field Value
Example
The following example shows how to handle the PivotGridControl.CustomDrawCell
event to paint Pivot Grid cells according to the cell’s state (selected or unselected) and the cell’s type (data cells or grand total cells).
The following image illustrates the resulting UI:
using DevExpress.XtraPivotGrid;
using System.Drawing;
using System.Windows.Forms;
namespace PivotCustomDraw {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
// This line of code is generated by Data Source Configuration Wizard
// Fill the ExcelDataSource
excelDataSource1.Fill();
}
private void pivotGridControl1_CustomDrawCell(object sender, PivotCustomDrawCellEventArgs e) {
Rectangle r;
// Paints Row Grand Totals.
if (e.RowValueType == PivotGridValueType.GrandTotal) {
Brush brushFillTotals;
brushFillTotals = e.GraphicsCache.GetSolidBrush(ColorTranslator.FromHtml("#0099cc"));
r = e.Bounds;
e.GraphicsCache.FillRectangle(brushFillTotals, e.Bounds);
r.Inflate(-4, -4);
e.GraphicsCache.DrawString(e.DisplayText, e.Appearance.Font,
Brushes.White, r, e.Appearance.GetStringFormat());
e.Handled = true;
return;
}
// Paints the data cells.
Brush brushFill;
r = e.Bounds;
if (e.Focused)
// Initializes the brush used to paint the focused cell.
brushFill = e.GraphicsCache.GetSolidBrush(Color.White);
else
if (e.Selected)
// Initializes the brush used to paint selected cells.
brushFill = e.GraphicsCache.GetSolidBrush(ColorTranslator.FromHtml("#b6e7eb"));
else
// Initializes the brush used to paint data cells.
brushFill = e.GraphicsCache.GetSolidBrush(ColorTranslator.FromHtml("#ecfbf8"));
e.GraphicsCache.DrawRectangle(Pens.DimGray, r);
r.Inflate(-1, -1);
e.GraphicsCache.FillRectangle(brushFill, r);
if (e.Focused) {
r.Inflate(-1, -1);
e.GraphicsCache.DrawRectangle(e.GraphicsCache.GetPen(ColorTranslator.FromHtml("#f05b41"),
3), r);
}
r.Inflate(-4, -4);
e.Appearance.DrawString(e.GraphicsCache, e.DisplayText, r);
e.Handled = true;
}
}
}
More Examples
Refer to the following section for more examples: Appearance
See Also