Skip to main content

How to: Create a Band Layout in Code

  • 3 minutes to read

The following code demonstrates how to create a band layout that contains three top-level bands and two nested bands, and associate these bands with columns.

Bands residing at the top hierarchy level are exposed by the TreeList.Bands collection. Each band within the collection exposes the TreeListBand.Bands property that provides access to the band’s child bands. In this example, three top-level bands (Main, Details and Picture) are created and added to the TreeList’s Bands collection. After that, two bands (Absolute Values and Related To Earth Values) are added to the Bands collection of the Details band.

To assign columns to bands, each column is added to the TreeListBand.Columns collection of an appropriate band.

The following image demonstrates the result of this code.

TreeListBandCustomizationInCodeResult

using DevExpress.XtraTreeList.Columns;

//...

//Clear the TreeList's band collection
treeList1.Bands.Clear();
//Make the band panel visible
treeList1.OptionsView.ShowBandsMode = DefaultBoolean.True;
//Enable the HTML formatting feature
treeList1.OptionsView.AllowHtmlDrawHeaders = true;
//Enable columns to be arranged in multiple rows
treeList1.OptionsView.AllowBandColumnsMultiRow = true;
//Disable the node auto height mode
treeList1.OptionsBehavior.AutoNodeHeight = false;

//Create the band layout
TreeListBand bandMain = treeList1.Bands.Add();
bandMain.Caption = "<b>Main</b>";
TreeListBand bandDetails = treeList1.Bands.Add();
bandDetails.Caption = "<b>Details</b>";
TreeListBand bandPicture = treeList1.Bands.Add();
bandPicture.Caption = "<b>Picture</b>";
TreeListBand bandAbsoluteValues = bandDetails.Bands.Add();
bandAbsoluteValues.Caption = "Absolute Values";
TreeListBand bandRelatedValues = bandDetails.Bands.Add();
bandRelatedValues.Caption = "Related To Earth Values";

//Assign columns to bands
bandMain.Columns.Add(colName);
bandMain.Columns.Add(colTypeOfObject);
bandAbsoluteValues.Columns.Add(colAbsoluteMeanRadius);
bandAbsoluteValues.Columns.Add(colAbsoluteVolume);
bandAbsoluteValues.Columns.Add(colAbsoluteMass);
bandRelatedValues.Columns.Add(colRelatedMeanRadius);
bandRelatedValues.Columns.Add(colRelatedVolume);
bandRelatedValues.Columns.Add(colRelatedMass);
bandPicture.Columns.Add(colIcon);

//Set the vertical position of column headers
colTypeOfObject.RowIndex = 1;
colAbsoluteMass.RowIndex = 1;
colRelatedMass.RowIndex = 1;

// Make columns visible (if they are hidden)
colName.Visible = true;
colTypeOfObject.Visible = true;
colAbsoluteMeanRadius.Visible = true;
colAbsoluteVolume.Visible = true;
colAbsoluteMass.Visible = true;
colRelatedMeanRadius.Visible = true;
colRelatedVolume.Visible = true;
colRelatedMass.Visible = true;
colIcon.Visible = true;