这里那里有错还是没错??? ( 积分: 50 )

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

YXBS2129

Unregistered / Unconfirmed
GUEST, unregistred user!
部门
业务部
张三
李四
企划部
....
财务部
....
上面的除了根(部门)其他都是来自数据库,我想知道如何用treeview控件来实现,
那么在窗体的OnCreate事件里如何用代码实现
Create Table DEPT (DEPTID char(10),DEPTMC char(10))
go
Insert Into DEPT
SELECT '001','业务部' Union All
Select '002','开发部' union all
select '003','测试部'
go
create table employee(ID char(10),deptid char(10),name(10))
go
insert into employee
select '0001','001','张三' union all
select '0002','001','李四' union all
select '0003','002','马五' union all
select '0004','003','赵六'
go

//以下是Delphi代码
procedure TForm1.Button1Click(Sender: TObject);
var vsl:TStringList;
stream_temp: TStringStream;
begin

ADOQ_DEPT.SQL.Text:='Select * From DEPT';
ADOQ_DEPT.Open;
vsl:=TStringList.Create;
vsl.Add('部门');
while not ADOQ_DEPT.Eofdo

begin

vsl.Add(#9+ADOQ_DEPT.FieldByName('DEPTMC').AsString);
ADOQ_DEPT.Close;
ADOQ_employee.SQL.Text:='Select * From employee Where DEPTID='+QuotedStr(ADOQ_employee.FieldByName('deptid').AsString);
ADOQ_employee.Open;
while not ADOQ_employee.Eofdo

begin

vsl.Add(#9#9+ADOQ_employee.FieldByName('NAME').AsString);
ADOQ_employee.Next;
end;

ADOQuery1.Next;
end;

stream_temp:=TStringStream.Create(vsl.Text);
TreeView1.LoadFromStream(stream_temp);
end;
 
帮你顶一个
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
2K
import
I
I
回复
0
查看
3K
import
I
I
回复
0
查看
2K
import
I
顶部