Skip to main content

BandedGridView.Columns Property

Provides access to the column collection.

Namespace: DevExpress.XtraGrid.Views.BandedGrid

Assembly: DevExpress.XtraGrid.v24.2.dll

Declaration

[Browsable(false)]
[XtraSerializableProperty(XtraSerializationVisibility.Collection, true, true, true, 0, XtraSerializationFlags.DefaultValue)]
[XtraSerializablePropertyId(2)]
public BandedGridColumnCollection Columns { get; }

Property Value

Type Description
BandedGridColumnCollection

A BandedGridColumnCollection object representing the View’s column collection.

Remarks

Use the Columns property to access an object that manages the View’s columns. You can use this property as an indexer to access columns by their indexes or bound field names. The GridBandColumnCollection.Add and GridBandColumnCollection.Remove methods enable you to add new or delete existing columns.

The Columns property overrides the ColumnView.Columns property since Banded Grid Views use BandedGridColumn objects to represent their columns. Please refer to the Columns topic for details.

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.

BandedGridView-example

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; }
    }
}
See Also