Skip to main content

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;