AdvTreeView - custom Checkbox images

The TTreeList supports custom checkbox images, is there a way to do this in the AdvTreeView?

There is a special descendant type: TAdvCheckedTreeView. It has checkboxes enabled by default

Thanks, but I have tried that now. It has checkboxes and I can set the image for the checkbox using an imagelist for the StateImages, but once the checkboxes are set to custom images they don't seem to work as checkboxes anymore. I can't see how to set the state/image of the checkbox or define which images equate to on/off and the AdvCheckTreeView1NodeCheckedChanged event is not fired.

Oops! getting confused by TAdvCheckedTreeView and TAdvCheckTreeView!

That's right, TAdvCheckedTreeView is the one to use.

Been trying that but the AdvCheckedTreeView is the same as the AdvTreeView, it just shows the check boxes by default. But it still does not support custom images for the checkboxes. The AdvCheckTree does support them but I can't see how to use them once they are showing. The NodeCheckedChanged event does not fire once the StateImages is set and I can't see how to specify which image is on/off

It does, but requires some custom drawing.

  1. Drop a TPictureContainer on the form and add check & uncheck icons (name them '0' & '1')
  2. Assign it to the PictureContainer property of the treeview
  3. Assign the OnBeforeDrawNodeCheck event
  4. Add the following code
procedure TForm22.AdvCheckedTreeView1BeforeDrawNodeCheck(Sender: TObject;
  AGraphics: TAdvGraphics; ARect: TRectF; AColumn: Integer;
  ANode: TAdvTreeViewVirtualNode; ACheck: TAdvBitmap; var AAllow: Boolean);
  AAllow := False;
  if not (ANode.Node as TAdvCheckedTreeViewNode).Checked[AColumn] then
    AGraphics.DrawBitmapWithName(ARect, '0')
    AGraphics.DrawBitmapWithName(ARect, '1');

1 Like

Thanks, I'll try that.