Back to Devexpress

GridOptionsView.AllowHtmlDrawGroups Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridoptionsview-643d32c0.md

latest5.4 KB
Original Source

GridOptionsView.AllowHtmlDrawGroups Property

Gets or sets whether HTML tags can be used to format text in group rows.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
[DefaultValue(true)]
[XtraSerializableProperty]
public virtual bool AllowHtmlDrawGroups { get; set; }
vb
<DefaultValue(True)>
<XtraSerializableProperty>
Public Overridable Property AllowHtmlDrawGroups As Boolean

Property Value

TypeDefaultDescription
Booleantrue

true if HTML tags can be used to format text in group rows; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to AllowHtmlDrawGroups
GridView

.OptionsView .AllowHtmlDrawGroups

|

Remarks

You can format text in group rows via the GridView.CustomDrawGroupRow event. To supply the new text for group rows, cast the event’s e.Info object to the GridGroupRowInfo object and then set the e.Info.GroupText property to the required value.

The HTML Text Formatting topic covers HTML tags you can use to format text.

Another way to format text in group rows is to use the GridView.GroupFormat property.

Example

The following example uses HTML tags to format text within group rows. The example handles the CustomDrawGroupRow event. In the example, when data is grouped by the “Quantity” column, group values are painted in different colors using the <color> tag. New display text for group rows is supplied via the e.Info.GroupText property.

csharp
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;

gridView1.OptionsView.AllowHtmlDrawGroups = true;

private void gridView1_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e) {
    GridView view = sender as GridView;
    GridGroupRowInfo info = e.Info as GridGroupRowInfo;
    if (info.Column.Caption == "Quantity") {
        int quantity = Convert.ToInt32(view.GetGroupRowValue(e.RowHandle, info.Column));
        string colorName = getColorName(quantity);
        info.GroupText = info.Column.Caption + ": <color=" + colorName + ">" + info.GroupValueText + "</color> ";
        info.GroupText += "<color=LightSteelBlue>" + view.GetGroupSummaryText(e.RowHandle) + "</color> ";
    }
}

string getColorName(int value) {
    if (value < 20) return "MediumOrchid";
    if (value >= 80) return "OrangeRed";
    return "Blue";
}
vb
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo

gridView1.OptionsView.AllowHtmlDrawGroups = True

Private Sub GridView1_CustomDrawGroupRow(sender As System.Object, _
    e As RowObjectCustomDrawEventArgs) Handles GridView1.CustomDrawGroupRow
    Dim view As GridView = TryCast(sender, GridView)
    Dim info As GridGroupRowInfo = TryCast(e.Info, GridGroupRowInfo)
    If info.Column.Caption = "Quantity" Then
        Dim quantity As Integer = Convert.ToInt32(view.GetGroupRowValue(e.RowHandle, info.Column))
        Dim colorName As String = getColorName(quantity)
        info.GroupText = info.Column.Caption & ": <color=" & colorName & ">" & info.GroupValueText & "</color> "
        info.GroupText &= "<color=LightSteelBlue>" & view.GetGroupSummaryText(e.RowHandle) & "</color> "
    End If
End Sub

Private Function getColorName(ByVal value As Integer) As String
    If value < 20 Then
        Return "MediumOrchid"
    End If
    If value >= 80 Then
        Return "OrangeRed"
    End If
    Return "Blue"
End Function

See Also

HtmlImages

HTML-inspired Text Formatting

GroupFormat

GridOptionsView Class

GridOptionsView Members

DevExpress.XtraGrid.Views.Grid Namespace