Skip to main content

GridBand.Columns Property

Gets columns owned by the band.

Namespace: DevExpress.XtraGrid.Views.BandedGrid

Assembly: DevExpress.XtraGrid.v24.2.dll

Declaration

[Browsable(false)]
[XtraSerializableProperty(XtraSerializationVisibility.NameCollection, true, true, true)]
[XtraSerializablePropertyId(3)]
public virtual GridBandColumnCollection Columns { get; }

Property Value

Type Description
GridBandColumnCollection

A GridBandColumnCollection object that contains band columns.

Remarks

Only bands located at the bottom of the bands hierarchy can have child columns. In other words, the Columns property of a band owning other bands returns an empty collection.

Use the Columns property to manage columns owned by a band. The GridBandColumnCollection object returned by this property enables you to add, delete and access individual columns. You can use the collection’s GridBandColumnCollection.Add or GridBandColumnCollection.Insert methods to add a column to the band (the column is first removed from its previous band and then added to the current one). The GridBandColumnCollection.Remove method can be used to remove the column from its current parent band. The column becomes invisible as a result.

Note

In Banded Grid Views, the column visual order within the parent band depends on the columns order within the Columns collection. Thus, you should move columns using the collection’s GridBandColumnCollection.MoveTo method to rearrange columns within the View.

Example: Create Child/Nesting Bands

The following example creates two bands and adds it to the root band’s Children collection:

WinForms Banded Grid View with Nested Bands, DevExpress

using DevExpress.XtraGrid.Views.BandedGrid;
using System;
using System.ComponentModel;

namespace DXApplication {
    public partial class Form1 : DevExpress.XtraEditors.XtraForm {
        public Form1() {
            InitializeComponent();
            gridControl1.DataSource = new BindingList<DataItem>() {
                new DataItem(){ StringProperty = "Value A", BooleanProperty = true, IntegerProperty = 10 },
                new DataItem(){ StringProperty = "Value B", BooleanProperty = true, IntegerProperty = 15 },
                new DataItem(){ StringProperty = "Value C", BooleanProperty = false, IntegerProperty = 20 },
            };
            this.Load += Form1_Load;
        }

        void Form1_Load(object sender, EventArgs e) {
            // Creates the first child band.
            GridBand childBand1 = rootBand.Children.AddBand("Child Band 1");
            // Adds the 'StringProperty' column to the first child band using the column's OwnerBand property.
            bandedGridView1.Columns["StringProperty"].OwnerBand = childBand1;
            // Adds the 'IntegerProperty' column to the first child band using the band.Columns.Add() method.
            childBand1.Columns.Add(bandedGridView1.Columns["IntegerProperty"]);

            // Creates the second child band.
            GridBand childBand2 = rootBand.Children.AddBand("Child Band 2");
            childBand2.Columns.Add(bandedGridView1.Columns["BooleanProperty"]);
        }
    }
    public class DataItem {
        public string StringProperty { get; set; }
        public int IntegerProperty{ get; set; }
        public bool BooleanProperty { get; set; }
    }
}
See Also