如何建立树形目录(50分)

  • 主题发起人 主题发起人 yuming_mail
  • 开始时间 开始时间
Y

yuming_mail

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么建立树形目录,还请各位大侠多多提点(举几个简单例子)。万分感谢!急急急!!!!
 
在Delphi的Demo中有一个例子,可以看看
 
我的一段程序,你参考一下!
procedure TFrmOperator.InitTreeView(TreeView1:TTreeView;Userid:string;has:Boolean);
var
AdoTemp,Adotemp1,adotemp2:TadoDataset;
TreeNode1,TreeNode2,TreeNode3:TTreeNode;
WhereSql,sql:string;
begin
TreeView1.Items.Clear;
if has then
WhereSql:=' and id in (select modulid from tblpower where No='''+userid+''')'
else
WhereSql:=' and id not in (select modulid from tblpower where No='''+userid+''')';
if Userid='All' then
WhereSql:='';
AdoTemp:=TadoDataset.Create(nil);
AdoTemp.Connection:=AdoConnection1;
AdoTemp.CommandText:='select * from Tblmodul where upid=''0''';
AdoTemp.Open;

if AdoTemp.IsEmpty then
begin
AdoTemp.Free;
exit;
end;
adotemp1:=Tadodataset.Create(nil);
adotemp1.Connection:=adoconnection1;

adotemp2:=Tadodataset.Create(nil);
adotemp2.Connection:=adoconnection1;


AdoTemp.First;
while not AdoTemp.Eof do
begin
new(TreeData);
TreeData^.id:=AdoTemp.fieldbyname('id').asstring;
TreeData^.name:=AdoTemp.fieldbyname('name').AsString;
TreeData^.Subitem:=AdoTemp.fieldbyname('Subitem').AsBoolean;
TreeData^.UpId:=AdoTemp.fieldbyname('Upid').AsString;
adotemp1.Close;
adotemp1.CommandText:='select * from tblmodul where upid='''+TreeData^.id+''''+WhereSql;
adotemp1.Open;
if adotemp1.IsEmpty then
begin
if TreeData^.Subitem =False then
begin
TreeNode1:=TreeView1.Items.Add(nil,TreeData^.name);
TreeNode1.Data :=TreeData;
end;
AdoTemp.Next;
continue;
end;
TreeNode1:=TreeView1.Items.Add(nil,TreeData^.name);
TreeNode1.Data :=TreeData;
adotemp1.First;
while not adotemp1.Eof do
begin
new(TreeData);
TreeData^.id :=adotemp1.fieldbyname('id').AsString;
TreeData^.name:=adotemp1.fieldbyname('name').AsString;
TreeData^.Subitem:=AdoTemp1.fieldbyname('Subitem').AsBoolean ;
TreeData^.UpId:=AdoTemp1.fieldbyname('Upid').AsString;
adotemp2.Close;
sql:='select * from tblmodul where upid='''+TreeData^.id+''''+WhereSql;
adotemp2.CommandText:=sql;
adotemp2.Open;
if adotemp2.IsEmpty then
begin
if TreeData^.Subitem =False then
begin
TreeNode2:=TreeView1.Items.AddChild(TreeNode1,TreeData^.name);
TreeNode2.Data :=TreeData;
end;
adotemp1.Next;
continue;
end;
TreeNode2:=TreeView1.Items.AddChild(TreeNode1,TreeData^.name);
TreeNode2.Data :=TreeData;
adotemp2.First;
while not adotemp2.Eof do
begin
new(TreeData);
TreeData^.id :=adotemp2.fieldbyname('id').AsString;
TreeData^.name:=adotemp2.fieldbyname('name').AsString;
TreeData^.Subitem:=AdoTemp2.fieldbyname('Subitem').AsBoolean ;
TreeData^.UpId:=AdoTemp2.fieldbyname('Upid').AsString;
TreeNode3:=TreeView1.Items.AddChild(TreeNode2,TreeData^.name);
TreeNode3.Data :=TreeData;
adotemp2.Next;
end;
adotemp1.Next;
end;
AdoTemp.Next;
end;
adotemp.free;
adotemp1.Free;
adotemp2.Free;

end;
 
in treeview control click right.
选中第一项然后编辑,
之后便可以在,treeview in see
last 在 treeview 的 click()
add
if treeview1.selectindex=0 then
...
 

Similar threads

D
回复
0
查看
897
DelphiTeacher的专栏
D
D
回复
0
查看
692
DelphiTeacher的专栏
D
D
回复
0
查看
654
DelphiTeacher的专栏
D
D
回复
0
查看
921
DelphiTeacher的专栏
D
后退
顶部