KB Article A272
Visible to All Users

How to customize the information shown on the group row

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\

Comments (2)
ZB ZB
Zvonko Boštjančič 10 years ago

    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";
          }

    Nadezhda (DevExpress Support) 10 years ago

      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.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.