Reputation: 1
this is the implementation for the treeview to have a check boxes in every nodes.
procedure TTreeView.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or TVS_CHECKBOXES;
end;
now, i want to get all the text of all checked nodes in treeview and append it in memo
Upvotes: 0
Views: 1827
Reputation: 27367
Sending a TVM_GETITEM message to the handle of a TreeItem will retrieve the needed state information in a TTVItem record defined in CommCtrl, if is called with the correct mask and ItemID.
The procedure TreeView_GetItem
doing this can be found (and copied) in CommCtrl.
So you just need to iterate over your treeview items an check if the state is checked.
{type
TTreeView = Class(ComCtrls.TTreeView)
procedure CreateParams(var Params: TCreateParams); override;
End;}
uses CommCtrl;
Function TreeNodeChecked(n:TTreenode):Boolean;
Const
TVIS_CHECKED = $2000;
var
Item: TTVItem;
begin
Item.mask := TVIF_STATE or TVIF_HANDLE;
Item.hItem := n.ItemId;
if Bool(SendMessage(n.Handle, TVM_GETITEM, 0, lParam(@Item))) then
Result := (Item.State and TVIS_CHECKED) = TVIS_CHECKED
else
Result := false;
end;
procedure TForm4.Button1Click(Sender: TObject);
var
i: Integer;
begin
ListBox1.Items.Clear;
for i := 0 to TV.Items.Count - 1 do
begin
if TreenodeChecked(TV.Items[i]) then
ListBox1.Items.Add(TV.Items[i].Text);
end;
end;
{ TTreeView }
procedure TTreeView.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or TVS_CHECKBOXES;
end;
Upvotes: 1