Description:
How can I customize the information shown on the group row?
Answer:
A common task when you need to construct your own text for your group rows is to remove the "FieldName: " prefix from the grouped row captions and leave only the field values of the grouped columns.
Modern XtraGrid versions (6.X and higher) provide the GroupFormat property, which allows a developer to customize the way GroupText is constructed. For this particular task, the GroupFormat property should be set as shown below:
C#gridView1.GroupFormat = "[#image]{1} {2}";
XtraGrid 2 provides the GroupFormat property for this purpose. If you need to output arbitrary text in a group row, you can use the CustomDrawGroupRow event and change the e.Info.DisplayText parameter. e.Info must be typecast to DevExpress.XtraGrid.Drawing.GridGroupRowInfoArgs. Here is some sample code:
C#private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e) {
DevExpress.XtraGrid.Drawing.GridGroupRowInfoArgs info;
info = e.Info as DevExpress.XtraGrid.Drawing.GridGroupRowInfoArgs;
info.DisplayText = "Some text";
}
XtraGrid 1 allows you to accomplish this by handling the CustomDrawGroupRow event. The attached samples illustrate how to format group captions, but you can use CustomDrawGroupRow to perform full painting of a group row and so change its appearance as your needs dictate.
Note: the attached projects should be placed in the same folder that the tutorial projects shipped with the installation are located, since it uses our sample data and can use the same relative path to find it. The default tutorial projects are:
<Program Files>\Developer Express Inc.NET\Demos\XtraGrid\CS\Tutorial\
<Program Files>\Developer Express Inc.NET\Demos\XtraGrid\VB\Tutorial\
This information is out of date. The correct implementation would be:
private void GridViewUpgradeStatus_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e)
{
var info = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo;
info.GroupText = "Some text";
}
Hello Zvonko,
Thank you for your message. This solution is effectively for older versions of our components. I have created the How to customize information shown in the group row example to display the solution for the latest versions.