Back to Devexpress

GridBand Class

windowsforms-devexpress-dot-xtragrid-dot-views-dot-bandedgrid-951f64a6.md

latest14.9 KB
Original Source

GridBand Class

Represents an individual band.

Namespace : DevExpress.XtraGrid.Views.BandedGrid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
public class GridBand :
    Component,
    IAppearanceOwner,
    IXtraSerializableLayoutEx,
    IAccessiblePropertiesProvider,
    ISupportDXSkinColorsEx,
    ISupportDXSkinColors,
    ISupportLookAndFeel,
    ISupportAppearanceObjectPropertiesFilter
vb
Public Class GridBand
    Inherits Component
    Implements IAppearanceOwner,
               IXtraSerializableLayoutEx,
               IAccessiblePropertiesProvider,
               ISupportDXSkinColorsEx,
               ISupportDXSkinColors,
               ISupportLookAndFeel,
               ISupportAppearanceObjectPropertiesFilter

The following members return GridBand objects:

Show 22 links

Remarks

Banded Grid Views and Advanced Banded Grid Views allow you to arrange columns into bands. Visually, bands are represented by their headers displayed over headers of the columns belonging to the band. Note that as well as arranging columns into logical groups, band headers can be dragged at runtime to rearrange bands or hide them, etc. Thus the layout and visibility of several columns can be controlled at once.

Individual bands are represented by GridBand objects. Note that banded Views allow you to arrange bands into a tree. Thus, band objects provide the GridBand.Children property that contains the band’s child band collection. Bands displayed at the root View level reside within the View’s BandedGridView.Bands collection. Note that columns can belong only to bands residing at the bottom hierarchy levels. To assign a column to a band you need to add the desired column to the band’s GridBand.Columns collection. Please refer to the Banded Grid Views and Rows topics for details.

Band objects are Component descendants. This enables you to access bands in code directly by their names.

Please refer to the Band Header and Banded Grid Views topics for additional information on bands.

Example

This example shows how to create a GridControl, while presenting its underlying data using a banded grid format (BandedGridView). The example creates three bands (Main, Address and Phone), adds columns to the bands and customizes the background color for the third band and its columns.

csharp
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.BandedGrid;

namespace DXApplication {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
            this.Load += Form1_Load;
        }
        private void Form1_Load(object sender, EventArgs e) {
            GridControl gridControl1 = new GridControl() { Parent = this, Dock = DockStyle.Fill };

            BandedGridView bandedGridView1 = new BandedGridView(gridControl1);
            GridBand gridBandMain = new GridBand() { Caption = "Main", VisibleIndex = 0 };
            GridBand gridBandAddress = new GridBand() { Caption = "Address", VisibleIndex = 1 };
            GridBand gridBandPhone = new GridBand() { Caption = "Phone", VisibleIndex = 2 };
            BandedGridColumn colCity = new BandedGridColumn() { FieldName = "City", Visible = true };
            BandedGridColumn colCompanyName = new BandedGridColumn() { FieldName = "CompanyName", Visible = true };
            BandedGridColumn colContactName = new BandedGridColumn() { FieldName = "ContactName", Visible = true };
            BandedGridColumn colCountry = new BandedGridColumn() { FieldName = "Country", Visible = true };
            BandedGridColumn colPhone = new BandedGridColumn() { FieldName = "Phone", Visible = true };
            BandedGridColumn colFax = new BandedGridColumn() { FieldName = "Fax", Visible = true };

            gridControl1.DataSource = new List<DataRecord>() {
                new DataRecord(){ City = "LA", CompanyName = "My Company", ContactName = "John White",
                   Country = "USA", Fax = "555-2211", Phone = "555-2212" }
            };
            gridControl1.ViewCollection.Add(bandedGridView1);
            gridControl1.MainView = bandedGridView1;

            bandedGridView1.Bands.AddRange(new GridBand[] { gridBandMain, gridBandAddress, gridBandPhone });
            bandedGridView1.Columns.AddRange(new BandedGridColumn[] { colCompanyName, colContactName, colCity, colCountry, colPhone, colFax });

            colPhone.AppearanceCell.BackColor = System.Drawing.Color.PowderBlue;
            colPhone.AppearanceCell.Options.UseBackColor = true;
            colPhone.AppearanceHeader.BackColor = System.Drawing.Color.PowderBlue;
            colPhone.AppearanceHeader.Options.UseBackColor = true;

            colFax.AppearanceCell.BackColor = System.Drawing.Color.PowderBlue;
            colFax.AppearanceCell.Options.UseBackColor = true;
            colFax.AppearanceHeader.BackColor = System.Drawing.Color.PowderBlue;
            colFax.AppearanceHeader.Options.UseBackColor = true;

            gridBandMain.Columns.Add(colCompanyName);
            gridBandMain.Columns.Add(colContactName);

            gridBandAddress.Columns.Add(colCountry);
            gridBandAddress.Columns.Add(colCity);

            gridBandPhone.AppearanceHeader.BackColor = System.Drawing.Color.LightBlue;
            gridBandPhone.AppearanceHeader.Options.UseBackColor = true;
            gridBandPhone.Columns.Add(colPhone);
            gridBandPhone.Columns.Add(colFax);

            bandedGridView1.OptionsCustomization.AllowChangeColumnParent = false;
        }
    }

    public class DataRecord {
        public string CompanyName{ get; set; }
        public string ContactName { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public string Phone { get; set; }
        public string Fax { get; set; }
    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.BandedGrid

Namespace DXApplication
    Partial Public Class Form1
        Inherits XtraForm

        Public Sub New()
            InitializeComponent()
            AddHandler Me.Load, AddressOf Form1_Load
        End Sub
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim gridControl1 As New GridControl() With {
                .Parent = Me,
                .Dock = DockStyle.Fill
            }

            Dim bandedGridView1 As New BandedGridView(gridControl1)
            Dim gridBandMain As New GridBand() With {
                .Caption = "Main",
                .VisibleIndex = 0
            }
            Dim gridBandAddress As New GridBand() With {
                .Caption = "Address",
                .VisibleIndex = 1
            }
            Dim gridBandPhone As New GridBand() With {
                .Caption = "Phone",
                .VisibleIndex = 2
            }
            Dim colCity As New BandedGridColumn() With {
                .FieldName = "City",
                .Visible = True
            }
            Dim colCompanyName As New BandedGridColumn() With {
                .FieldName = "CompanyName",
                .Visible = True
            }
            Dim colContactName As New BandedGridColumn() With {
                .FieldName = "ContactName",
                .Visible = True
            }
            Dim colCountry As New BandedGridColumn() With {
                .FieldName = "Country",
                .Visible = True
            }
            Dim colPhone As New BandedGridColumn() With {
                .FieldName = "Phone",
                .Visible = True
            }
            Dim colFax As New BandedGridColumn() With {
                .FieldName = "Fax",
                .Visible = True
            }

            gridControl1.DataSource = New List(Of DataRecord)() From {
                New DataRecord() With {
                    .City = "LA",
                    .CompanyName = "My Company",
                    .ContactName = "John White",
                    .Country = "USA",
                    .Fax = "555-2211",
                    .Phone = "555-2212"
                }
            }
            gridControl1.ViewCollection.Add(bandedGridView1)
            gridControl1.MainView = bandedGridView1

            bandedGridView1.Bands.AddRange(New GridBand() { gridBandMain, gridBandAddress, gridBandPhone })
            bandedGridView1.Columns.AddRange(New BandedGridColumn() { colCompanyName, colContactName, colCity, colCountry, colPhone, colFax })

            colPhone.AppearanceCell.BackColor = System.Drawing.Color.PowderBlue
            colPhone.AppearanceCell.Options.UseBackColor = True
            colPhone.AppearanceHeader.BackColor = System.Drawing.Color.PowderBlue
            colPhone.AppearanceHeader.Options.UseBackColor = True

            colFax.AppearanceCell.BackColor = System.Drawing.Color.PowderBlue
            colFax.AppearanceCell.Options.UseBackColor = True
            colFax.AppearanceHeader.BackColor = System.Drawing.Color.PowderBlue
            colFax.AppearanceHeader.Options.UseBackColor = True

            gridBandMain.Columns.Add(colCompanyName)
            gridBandMain.Columns.Add(colContactName)

            gridBandAddress.Columns.Add(colCountry)
            gridBandAddress.Columns.Add(colCity)

            gridBandPhone.AppearanceHeader.BackColor = System.Drawing.Color.LightBlue
            gridBandPhone.AppearanceHeader.Options.UseBackColor = True
            gridBandPhone.Columns.Add(colPhone)
            gridBandPhone.Columns.Add(colFax)

            bandedGridView1.OptionsCustomization.AllowChangeColumnParent = False
        End Sub
    End Class

    Public Class DataRecord
        Public Property CompanyName() As String
        Public Property ContactName() As String
        Public Property City() As String
        Public Property Country() As String
        Public Property Phone() As String
        Public Property Fax() As String
    End Class
End Namespace

Inheritance

Object MarshalByRefObject Component GridBand

See Also

GridBand Members

AdvBandedGridView

BandedGridView

Banded Grid Views

DevExpress.XtraGrid.Views.BandedGrid Namespace