用数据表创建树
2006-02-04 13:52:13 来源:WEB开发网数据库结构:
字段 类型
ID 整型 索引(无重复)
name 文本
father 整型
//tree初始化
PRocedure TForm1.FormActivate(Sender: TObject);
var i:integer;
begin
treeview1.Items.BeginUpdate;
while not(adotable1.Eof) do
begin
if ADOTable1.FieldValues['father']=0 then
treeview1.Items.addchild(treeview1.DropTarget,ADOTable1.FieldValues['name'])
else
begin
i:=0;
repeat
if treeview1.Items.Item[i].Text = ADOTable1.Lookup('ID',ADOTable1.FieldValues['father'],'name') then
begin
treeview1.Items.AddChild(treeview1.Items.Item[i],ADOTable1.FieldValues['name']);
break;
end;
i:=i+1;
until i>adotable1.RecordCount;
end;
ADOTable1.next;
end;
treeview1.Items.EndUpdate;
end;
//tree添加
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
adotable1.Last;
i:=adotable1.FieldValues['ID'];
if checkbox1.Checked=false then
begin
adotable1.InsertRecord([edit1.Text,adotable1.Lookup('name',treeview1.Selected.Text,'ID'),i+1]);
treeview1.Items.AddChild(treeview1.Selected,edit1.Text);
end
else
begin
adotable1.InsertRecord([edit1.Text,0,i+1]);
treeview1.Items.AddChild(treeview1.DropTarget,edit1.Text);
end;
end;
//tree删除
procedure TForm1.Button3Click(Sender: TObject);
begin
if treeview1.Selected.HasChildren then
begin
showmessage('含有子项,不能删除.');
abort;
end;
begin
adotable1.Locate('name',treeview1.Selected.Text,[loPartialKey]);
adotable1.Delete;
treeview1.Items.Delete(treeview1.Selected);
end;
end;
//tree图标
procedure TForm1.TreeView1GetImageIndex(Sender: TObject; Node: TTreeNode);
begin
if Node.Expanded then
Node.ImageIndex := 1
else
Node.ImageIndex := 0
end;
//tree图标
procedure TForm1.TreeView1GetSelectedIndex(Sender: TObject;Node: TTreeNode);
begin
node.SelectedIndex:=node.ImageIndex;
end;
//list初始化
procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
var p:pointer;
begin
listview1.Items.Clear;
if adotable2.Locate('class',adotable1.Lookup('name',treeview1.Selected.Text,'ID'),[loPartialKey])=true then
begin
p:=listview1.Items.Add;
listview1.Items.Item[listview1.Items.IndexOf(p)].Caption:=adotable2.FieldValues['name'];
listview1.Items.Item[listview1.Items.IndexOf(p)].SubItems.Add(adotable2.FieldValues['url']);
end;
end;
//list添加
procedure TForm1.Button2Click(Sender: TObject);
var p:pointer;
begin
p:=listview1.Items.Add;
listview1.Items.Item[listview1.Items.IndexOf(p)].Caption:=edit2.Text;
listview1.Items.Item[listview1.Items.IndexOf(p)].SubItems.Add(edit3.Text);
adotable2.InsertRecord([adotable1.Lookup('name',treeview1.Selected.Text,'ID'),edit2.Text,edit3.Text]);
end;
//list删除
procedure TForm1.Button4Click(Sender: TObject);
begin
adotable2.Locate('name',listview1.Selected.Caption,[loPartialKey]);
adotable2.Delete;
listview1.Selected.Delete;
end;
- ››创建SQL2005自动备份,定期删除的维护计划
- ››创建动态表单 javascript
- ››创建基于PPTP的站点到站点VPN连接:ISA2006系列之...
- ››创建基于L2TP的站点到站点的VPN连接:ISA2006系列...
- ››创建一个Twisted Reactor TCP服务器
- ››创建Windows Mobile上兼容性好的UI 程序
- ››创建android的Service
- ››创建远古部落环境与原住民角色
- ››创建并扩展Apache Wicket Web应用
- ››创建不在任务条中显示窗口按钮的应用
- ››创建 Android 文件系统(Root file system)
- ››数据表空间的重用(Reusing space in a table)
更多精彩
赞助商链接