Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Example: Bands.Add, Bands.Count, Bands

  • 2 minutes to read

The following sample shows how to add a new band to the tree list control. The miAddBandClick method invokes a dialog box that allows the end-user to provide the new band’s caption. The miAddBandClick event calls the GetBandByCaption method, which checks if a band with the caption specified already exists.

procedure <Form>.miAddBandClick(Sender: TObject);
var
  ABandCaption: String;
begin
  if InputQuery('Create band', 'Specify a caption of the band', ABandCaption) then
    if GetBandByCaption(ABandCaption) <> nil then
      MessageDlg('Band with this caption already exists', mtWarning, [mbOK], 0)
    else
      with cxDBTreeList.Bands.Add do
        begin
          Caption.Text := ABandCaption;
          Caption.AlignHorz := taCenter;
        end;
end;
function <Form>.GetBandByCaption(ABandCaption: String): TcxTreeListBand;
var
  I: Integer;
begin
  Result := nil;
  for I := 0 to cxDBTreeList.Bands.Count - 1 do
    if cxDBTreeList.Bands[I].Caption.Text = ABandCaption then
    begin
      Result := cxDBTreeList.Bands[I];
      Break;
    end;
end;