Skip to main content

TcxTreeListStyles.OnGetBandContentStyle Event

Occurs for each node within a band whenever the band’s contents need repainting.

Declaration

property OnGetBandContentStyle: TcxTreeListGetBandContentStyleEvent read; write;

Remarks

This event occurs every time the TreeList band’s content is repainted. This allows you to substitute the assigned band content style by another style.

To change the style, you should write an event handler that passes the existing instance of the TcxStyle class to the control via the AStyle parameter. Note that the AStyle parameter doesn’t represent any TcxStyle instance and is nil by default. So you can’t implement the following code:

AStyle.Color := clBlack

before you assign a TcxStyle instance to it.

The following code is not recommended either:

AStyle := TcxStyle.Create;

In this case, a TcxStyle instance will be created every time the event occurs and it will never be removed until application termination. Implementing the above code creates excessive TcxStyle instances and excessive memory usage as the result. The correct method is to create a TcxStyle instance outside the event handler and pass it to the control via the AStyle parameter within the event handler. For instance, you can use the StyleRepository to create and store your custom styles.

The Sender parameter of the event contains the TreeList control instance that owns the style collection.

The ABand parameter contains the TreeList band whose content is being repainted.

The ANode parameter specifies the Tree list node whose content is defined.

The following sample code shows how to specify the band’s content color using the OnGetBandContentStyle event. The handler only changes the color of the first visible band within the control (see IsLeftMost).

var
  InternalStyle: TcxStyle; // defines a global style variable
//...
procedure TFormMain.tlMainStylesGetBandContentStyle(Sender: TcxCustomTreeList; ABand: TcxTreeListBand; ANode: TcxTreeListNode; var AStyle: TcxStyle);
begin
  if not ABand.IsLeftMost then Exit;
  if (InternalStyle = nil) then
  begin
    InternalStyle := TcxStyle.Create(nil);
    InternalStyle.Color := $E6F0FA;
  end;
  AStyle := InternalStyle;
end;

The initial style for the band’s content is determined by the TcxTreeListStyles.BandContent property.

See Also