谁能提供个把数据库显示在TREEVIEW里的例子,并有添加、删除任意层次接点的数据!!!(0分)

  • 主题发起人 主题发起人 wangchengwu
  • 开始时间 开始时间
W

wangchengwu

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能提供个把数据库显示在TREEVIEW里的例子,并有添加、删除任意层次接点的数据!!!
 
用dbtreeview可以实现
 
有很多控件可以实现,关键要看你的数据结构。
 
用dxdbtreeview控件很容易实现的啊
 
procedure tf_dwzd.treerefresh;
var node1,node2:ttreenode;
i,j:integer;
strnode1,strnode2:string;
begin
with tv1 do
begin
Items.Clear;
node1:=Items.Add (nil,'行政机构名称');
query1.Close;
query1.sql.Clear;
query1.sql.add('select * from xzdwzd order by dwbh');
query1.open;
query1.first;
for i:=0 to query1.RecordCount-1 do
begin
strnode1:=query1.fieldbyname('dwbh').asstring+' '+query1.fieldbyname('dwmc').asstring;
node2:=items.AddChild(node1,strnode1);
query2.Close;
query2.sql.Clear;
query2.sql.add('select dwbh,dwmc from xzdwzd1 where left(dwbh,4)='''+query1.fieldbyname('dwbh').asstring+''' order by dwbh');
query2.open;
if not query2.eof then
begin
query2.first;
for j:=0 to query2.RecordCount-1 do
begin
strnode2:=query2.fieldbyname('dwbh').asstring+' '+query2.fieldbyname('dwmc').asstring;
items.AddChild (node2,strnode2);
query2.next;
end;
end;
query1.next;
end;
end;
end;
 
建议不要用第三方控件,否则很不好随心所意地控制,自己写程序实现,不难的,树控件用递归方法
实现无限深度级的数据结构很方便。
 
to delphilai
我感到有些困难,如果你方便或者有这方面的代码,请给我一份。
email :shgproduct@163.com
 
用递归实现!
 
TReTS = record
ClassId: string;
Des: string;
CType: string;
DocTable: string;
BoxTable: string;
RoolTable: string;
end;
TTreeData = class
ClassId: string;
Des: string;
CType: string;
DocTable: string;
BoxTable: string;
RoolTable: string;
Security:string;
SCREENNAME:string;
procedure CopyData(Data: TReTS);
end;

procedure AddTree(MyQuery: tquery; MyTree: TtreeView; MyNode: TTreeNode;
ClassId, ClassT: string);
//向TREEVIEW中添加数据,使用递归
var
MNode: TTreeNode;
intl, intI: integer;
MySele: array[0..99] of TReTS;
TreeData: TTreedata;
strSQL: string;
begin
case strtoint(ClassT) of
0, 1:
begin
if MyNode = nil then MyNode := MyTree.Items.Item[0];
strsql := ' AND (CLASSTYPE=''0'' OR CLASSTYPE=''1'')';
end;
2:
begin
if MyNode = nil then MyNode := MyTree.Items.Item[1];
strsql := ' AND CLASSTYPE=''2''';
end;
3:
begin
if MyNode = nil then MyNode := MyTree.Items.Item[2];
strsql := ' AND CLASSTYPE=''3''';
end;
else
strsql := '';
end;
//
MyQuery.Filtered := false;
MyQuery.Filter := 'PARENTECLASSID=''' + ClassId + '''' + STRSQL+' AND CLASSLEVEL>6';
MyQuery.Filtered := true;
//
if MyQuery.IsEmpty <> true then
begin
MyQuery.First;
intl := 0;
while TRUE do
begin
if MYQUERY.Eof then BREAK;
MySele[intl].ClassId := MyQuery.FieldByName('ClassId').AsString;
MySele[intl].Des := MyQuery.FieldByName('DESCRIPTION').AsString;
MySele[intl].CType := MyQuery.FieldByName('ClassType').AsString;
MySele[intl].DocTable := MyQuery.FieldByName('DocTable').AsString;
MySele[intl].BoxTable := MyQuery.FieldByName('BoxTable').AsString;
MySele[intl].RoolTable := MyQuery.FieldByName('ROOLTABLE').AsString;
;
MyQuery.Next;
intl := intl + 1;

end;

for inti := 0 to intl - 1 do
begin
mytree.Items.BeginUpdate;
MNode := mytree.Items.AddChild(MyNode, MySele[inti].Des);
mytree.Items.EndUpdate;
case strtoint(MySele[inti].CType) of
0:
begin
MNode.ImageIndex := 0;
MNode.SelectedIndex := 1;
MNode.StateIndex := 1;
end;
1:
begin
MNode.ImageIndex := 2;
MNode.SelectedIndex := 2;
MNode.StateIndex := 2;
end;
2:
begin
MNode.ImageIndex := 0;
MNode.SelectedIndex := 1;
MNode.StateIndex := 1;
end;
3:
begin
MNode.ImageIndex := 2;
MNode.SelectedIndex := 2;
MNode.StateIndex := 2;
end;
else
showmessage('数据库错误!');
end;
TreeData := tTreeData.Create;
TreeData.CopyData(MySele[inti]);
MNode.Data := TreeData;
AddTree(MyQuery, MyTree, MNode, MySele[inti].ClassId, '-1');
end;
end;
end;
写的很烂多多包涵
 

Similar threads

S
回复
0
查看
730
SUNSTONE的Delphi笔记
S
S
回复
0
查看
738
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部