procedure loadUser(Sender: TObject; qry1, qry2: TADOQuery; tree: TspSkinTreeView; var treeNode1, treeNode2, treeNode3: TTreeNode);
//tree: TspSkinTreeView为皮肤控件类型
procedure TfrmUserMgr.loadUser(Sender: TObject; qry1, qry2: TADOQuery; tree: TspSkinTreeView; var treeNode1, treeNode2, treeNode3: TTreeNode);
begin
with qry1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from user');
Open;
end;
Case qry1.fieldbyname('user_rights').AsInteger of
0:
begin
treeNode1 := tree.Items.Add(nil,'管理员');
with qry2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from user where user_rights=0');
Open;
end;
while not qry2.Eof do
begin
tree.Items.Add(treeNode1,qry2.fieldbyname('user_name').AsString);
qry2.Next;
end;
end;
1:
begin
treeNode2:=tree.Items.Add(nil,'操作员');
with qry2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from user where user_rights=1');
Open;
end;
while not qry2.Eof do
begin
tree.Items.Add(treeNode2,qry2.fieldbyname('user_name').AsString);
qry2.Next;
end;
end;
2:
begin
treeNode3:=tree.Items.Add(nil,'普通用户');
with qry2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from user where user_rights=2');
Open;
end;
while not qry2.Eof do
begin
tree.Items.Add(treeNode3,qry2.fieldbyname('user_name').AsString);
qry2.Next;
end;
end;
qry1.next;
end;
end;
要实现
0---|管理员----|用户a
| |用户b
| |用户c
1---操作员----|用户d
| |用户e
| |用户f
2---|普通用户--|用户g
应该如何修改代码?现在能显示所有内容,但是比如操作员有N个用户,那么就会出现N个操作员的根节点,哪位大虾帮忙?
delphi treeview根节点中添加节点的问题(急)
答案:1 悬赏:80 手机版
解决时间 2021-04-16 20:29
- 提问者网友:遁入空寂
- 2021-04-16 07:44
最佳答案
- 五星知识达人网友:雾月
- 2021-04-16 09:18
begin
treeNode2:=tree.Items.Add(nil,'操作员');
with qry2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from user where user_rights=1');
Open;
end;
while not qry2.Eof do
begin
// 注意这里,只要把Add改成AddChild就可以了 tree.Items.AddChild(treeNode2,qry2.fieldbyname('user_name').AsString);
qry2.Next;
end;
end;
其它类同,
TTreeView.Items.Add是添加根结点
TTreeView.Items.AddChild是在第一个参数指示的节点下添加一个节点
treeNode2:=tree.Items.Add(nil,'操作员');
with qry2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from user where user_rights=1');
Open;
end;
while not qry2.Eof do
begin
// 注意这里,只要把Add改成AddChild就可以了 tree.Items.AddChild(treeNode2,qry2.fieldbyname('user_name').AsString);
qry2.Next;
end;
end;
其它类同,
TTreeView.Items.Add是添加根结点
TTreeView.Items.AddChild是在第一个参数指示的节点下添加一个节点
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯