方法一:delphi中递归算法构建treeView过程:通过读取数据库中table1的数据,来构建一颗树。table1有两个字段:ID,preID,即当前结点标志和父结点标志。所以整个树的表示为父母表示法。本递归算法不难写,但是要注意:程序内部的变量都应使用局部变量!比如当Query是外部变量(函数外定义或者直接通过控件拖拽得来)时就会得到错误的结果。代码如下: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, ...
方法一:delphi中递归算法构建treeView过程:通过读取数据库中table1的数据,来构建一颗树。table1有两个字段:ID,preID,即当前结点标志和父结点标志。所以整个树的表示为父母表示法。本递归算法不难写,但是要注意:程序内部的变量都应使用局部变量!比如当Query是外部变量(函数外定义或者直接通过控件拖拽得来)时就会得到错误的结果。代码如下: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, ...
在 DragDrop 的时候,滚动 TreeView当高度不够的时候 procedure TForm1.TreeView1DragOver(Sender, Source:
TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);begin if (y <15) then {On
the upper edge - should scroll up
} SendMessage(TreeView1.Handle,
WM_VSCROLL, SB_LINEUP, 0) elseif
(TreeView1.Height - y <15) then { On
the lower edge - should scroll down
} SendMessage...
1 unit Unit2;2 3 interface4 5 uses6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.Grids,8 Vcl.DBGrids, Vcl.ComCtrls, Vcl.StdCtrls;9 10 type11 TForm2 = class(TForm)12 TreeView1: TTreeView;13 DBGrid1: TDBGrid;14 ADOConnection1: TADOConnection;15 ADOQuery1: TA...
procedure TUIOperate.FillTree(treeview: TTreeView);
var
? findq: TADOQuery;
? node: TTreeNode;
?
? //这个方法是根据记录的id字段值,查找TreeView上的父节点
? function FindParentNode(id:Integer):TTreeNode;
? var
? ? i:Integer;
? begin
? ? Result := nil;
? ? for i := 0 to treeview.Items.Count - 1 do
? ? begin
? ? ? //比较Node的Data值和记录的id值
? ? ? if Integer(treeview.Items[i].Data) = id then
? ? ?...
方法一:delphi中递归算法构建treeView
过程:通过读取数据库中table1的数据,来构建一颗树。table1有两个字段:ID,preID,即当前结点标志和父结点标志。所以整个树的表示为父母表示法。本递归算法不难写,但是要注意:程序内部的变量都应使用局部变量!比如当Query是外部变量(函数外定义或者直接通过控件拖拽得来)时就会得到错误的结果。代码如下:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Clas...
procedure TUIOperate.FillTree(treeview: TTreeView);
var
findq: TADOQuery;
node: TTreeNode;
//这个方法是根据记录的id字段值,查找TreeView上的父节点
function FindParentNode(id:Integer):TTreeNode;
var
i:Integer;
begin
Result := nil;
for i := 0 to treeview.Items.Count - 1 do
begin
//比较Node的Data值和记录的id值
if Integer(treeview.Items[i].Data) = id then
...
本例效果图:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, DBClient, StdCtrls, ComCtrls, ExtCtrls;type
TForm1 = class(TForm)
DataSource1: TDataSource;
ClientDataSet1: TClientDataSet;
DBGrid1: TDBGrid;
TreeView1: TTreeView;
Splitter1: TSplitter;
procedure FormCreate(Sender: TObject);
p...
方法一:delphi中递归算法构建treeView
过程:通过读取数据库中table1的数据,来构建一颗树。table1有两个字段:ID,preID,即当前结点标志和父结点标志。所以整个树的表示为父母表示法。本递归算法不难写,但是要注意:程序内部的变量都应使用局部变量!比如当Query是外部变量(函数外定义或者直接通过控件拖拽得来)时就会得到错误的结果。代码如下:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Clas...