Friday, February 15, 2008

Adding CheckBox to a TShellTreeView


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ShellCtrls,
ComCtrls;

type
TCheckBoxShellTreeView = class(TShellTreeView)
public
procedure CreateParams(var Params: TCreateParams); override;
end;

TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FShellTreeView: TCheckBoxShellTreeView;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

const
TVS_CHECKBOXES = $00000100;

procedure TCheckBoxShellTreeView.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or TVS_CHECKBOXES;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FShellTreeView := TCheckBoxShellTreeView.Create(Self);
with FShellTreeView do
begin
Name := 'FShellTreeView';
Parent := Self;
Root := 'rfDesktop';
UseShellImages := True;
Align := alClient;
AutoRefresh := False;
BorderStyle := bsNone;
Indent := 19;
ParentColor := False;
RightClickSelect := True;
ShowRoot := False;
TabOrder := 0;
end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FShellTreeView.Free;
end;

end.

1 comment:

GreatDayDan said...

Good Morning!

I am using a TTreeView with "Params.Style:= Params.Style or TVS_CHECKBOXES;"
procedure TgddTreeView.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style:= Params.Style or TVS_CHECKBOXES;
end;

This is allowing me to toggle the checkboxes, but, how do I read the checkbox state?

Thanks...Dan'l