Back to Devexpress

GridView.GroupFormat Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-a216ca5f.md

latest6.4 KB
Original Source

GridView.GroupFormat Property

Gets or sets the format rule that specifies a template for group row captions. You can build this template from custom text strings and the following placeholders: {0}, {1}, {2} and [#image].

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue("{0}: [#image]{1} {2}")]
[DXCategory("Appearance")]
[XtraSerializableProperty]
public virtual string GroupFormat { get; set; }
vb
<DefaultValue("{0}: [#image]{1} {2}")>
<XtraSerializableProperty>
<DXCategory("Appearance")>
Public Overridable Property GroupFormat As String

Property Value

TypeDefaultDescription
String"{0}: [#image]{1} {2}"

A string value specifying the text pattern for group rows.

|

Remarks

The default group format contains all four available placeholders: “{0}: [#image]{1} {2}”. For instance, “Category: <Image> Seafood (Count = 26)”.

  • {0} - the group column caption. In the example above, {0} is a placeholder for “Category”.

  • {1} - the group column display text. In the example above, {1} is a placeholder for food categories (“Seafood”, “Grains and Cereals”, etc.). The {1} placeholder may insert a text string that differs from cell values. This happens when:

  • {2} - the group row summary text. In the example above, the {2} placeholder inserts the value of a summary item that calculates the number of records in each group. The code below creates a group summary item whose value is shown by the {2} placeholder.
csharp
gridView.GroupSummary.Add(new GridGroupSummaryItem() {
FieldName = "UnitPrice",
SummaryType = SummaryItemType.Count,
ShowInGroupColumnFooter = null
});
vb
gridView.GroupSummary.Add(New GridGroupSummaryItem() With {
.FieldName = "UnitPrice",
.SummaryType = SummaryItemType.Count,
.ShowInGroupColumnFooter = Nothing})

If you add multiple group row summaries, the {2} placeholder shows comma-separated values for all of them. For example: “Category: Beverage (Count=12),(MAX = 4.50)”.

  • [#image] - the group row image. To specify group row images, assign an ImageComboBox in-place editor (RepositoryItemComboBox) to a group column. Use the GridColumn.ColumnEdit property to specify an in-place editor.

Use the GridView.GetGroupRowDisplayText method to return the currently displayed group row text.

The GroupFormat property affects all group rows in a View. You can also handle the GridView.CustomDrawGroupRow event to modify individual group rows’ captions (for instance, to add HTML tags).

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GroupFormat property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-conditionally-hide-summaries-from-group-rows/CS/ConditionallyHideSumsInGroupRows/Form1.cs#L27

csharp
gridView1.Columns["Discontinued"].Group();
    gridView1.GroupFormat = "{0}: [#image]{1} "; // summaries are hidden for simpler string composing in CustomDrawGroupRow
}

winforms-grid-conditionally-hide-summaries-from-group-rows/VB/ConditionallyHideSumsInGroupRows/Form1.vb#L28

vb
gridView1.Columns("Discontinued").Group()
    gridView1.GroupFormat = "{0}: [#image]{1} " ' summaries are hidden for simpler string composing in CustomDrawGroupRow
End Sub

See Also

GroupFormat

GroupInterval

Data Grouping

CustomDrawGroupRow

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace