Skip to main content

Example: OnGetNodeImageIndex

The following example shows how to handle the OnGetNodeImageIndex event. The event handler specifies the custom node image depending on the node level and the node’s hot-track state.

procedure <Form>.<TreeList>GetNodeImageIndex(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; AIndexType: TcxTreeListImageIndexType; var AIndex: TImageIndex);
begin
// exit from the handler if the currently handled image is a state image or a overlay state image
  if AIndexType in [tlitStateIndex, tlitOverlayStateIndex] then Exit;
  if ANode.Level = 0 then
  begin
    AIndex := 0;
    if ANode.Expanded then
      Inc(AIndex);
  end
  else
    AIndex := 4;
    if ANode.HotTrack then
      if ANode.Level = 0 then
        Inc(AIndex, 2)
      else
        Inc(AIndex);
end;