• 学习 TTreeView [16]


    问题来源: http://www.cnblogs.com/del/archive/2008/05/15/1114450.html#1199402

    本例效果图:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls;
    
    type
      TForm1 = class(TForm)
        TreeView1: TTreeView;
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses CommCtrl;
    
    //让 TreeView 带有复选框
    procedure TForm1.FormCreate(Sender: TObject);
    var
      H: HWND;
    begin
      H := TreeView1.Handle;
      SetWindowLong(H, GWL_STYLE, GetWindowLong(H, GWL_STYLE) or TVS_CHECKBOXES);
    
      {下面的代码只是给 TreeView 添加内容}
      with TreeView1 do
      begin
        Align := alLeft;
        Items.Add(nil, 'AAA');
        Items.Add(nil, 'BBB');
        Items.Add(nil, 'CCC');
        Items.AddChild(Items[2], '111');
        Items.AddChild(Items[2], '222');
        Items.AddChild(Items[2], '333');
      end;
    end;
    
    //列举带有复选框的项
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Node: TTreeNode;
      TVI: TTVItem;
    begin
      for Node in TreeView1.Items do
      begin
        TVI.mask := TVIF_STATE;
        TVI.hItem := Node.ItemId;
        TreeView_GetItem(TreeView1.Handle, TVI);
        if TVI.state and $2000 = $2000 then
          ShowMessage(Node.Text);
      end;
    end;
    
    //取消所有选中(这是后来补充的, 所以效果图上没有)
    procedure TForm1.Button2Click(Sender: TObject);
    var
      Node: TTreeNode;
      TVI: TTVItem;
    begin
      for Node in TreeView1.Items do
      begin
        TVI.mask := TVIF_STATE;
        TVI.hItem := Node.ItemId;
        TVI.stateMask := TVIS_STATEIMAGEMASK;
        TVI.state := $2000 shr 1;
        TreeView_SetItem(TreeView1.Handle, TVI);
      end;
    end;
    
    //选中所有(这是后来补充的, 所以效果图上没有)
    procedure TForm1.Button3Click(Sender: TObject);
    var
      Node: TTreeNode;
      TVI: TTVItem;
    begin
      for Node in TreeView1.Items do
      begin
        TVI.mask := TVIF_STATE;
        TVI.hItem := Node.ItemId;
        TVI.stateMask := TVIS_STATEIMAGEMASK;
        TVI.state := $2000;
        TreeView_SetItem(TreeView1.Handle, TVI);
      end;
    end;
    
    end.
  • 相关阅读:
    前端之HTML
    python 迭代器、生成器、装饰器
    python实现线程池
    Archiva与maven配置使用
    Jenkins在windows环境下安装无法安装插件
    ②Jenkins集成—集成构建部署
    linux环境下maven的安装配置
    linux环境下git的安装配置
    ①Jenkins集成—入门安装使用
    Ant build.xml相关属性详解
  • 原文地址:https://www.cnblogs.com/jijm123/p/11374367.html
Copyright © 2020-2023  润新知