delphi怎样在dbgrid中显示树形结构字段
5个回答
展开全部
以下是个人treeview的树的编程源码(已经在个人的4年商业软件中运行,这里奉献给想学习的年轻人),由于无法传递附件,只好复制如下(复制本单元窗体的 public部分文件,在其他窗体中用uses调用 即可使用)
unit sdlformtree;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, ExtCtrls, ComCtrls,DBClient, DBCtrls;
type
TFormsdltree = class(TForm)
TreeView1: TTreeView;
Panel14: TPanel;
BtnMakeTree: TButton;
BtnAddChildNode: TButton;
BtnAddNode: TButton;
BtnDeleteTree: TButton;
BtnFind: TButton;
EdFindText: TEdit;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
procedure BtnMakeTreeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BtnAddNodeClick(Sender: TObject);
procedure BtnAddChildNodeClick(Sender: TObject);
procedure BtnDeleteTreeClick(Sender: TObject);
procedure DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
procedure BtnFindClick(Sender: TObject);
private
public
//==============================================================================
// 本单元实现了TreeView与数据的关联,其各项要求如下:
//
// 数据库这里采用了Interbase表,使用三层技术编程的方法,表中的字段要
// 有id,pid,caption三个。
// id: 为自增字段,用于表示节点的编号。
// caption: 用来表示在树中所要显示的内容。
// pid: 用来表示当前节点的父节点。
//在这个城市地区例子中,有 city_infor_ID、city_infor_Name和city_infor_privence_ID
//三个字段。
//==============================================================================
{-------------------------------------------------------------------------------
过程名: MakeTree
说明: 创建树
作者: DLS
日期: 2006.08.19
参数: ClientDataSetName: string; TreeView: TTreeView
参数说明: ClientDataSetName: 对应的客户数据集名; TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure MakeTree(ClientDataSetName: string; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: AddNode
说明: 增加树的节点
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure AddNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: AddChildNode
说明: 增加树的子节点
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure AddChildNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: AddTreeNode
说明: 增加节点(内部使用的过程)
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView; bj: boolean = false
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树;
bj:是否将焦点移到当前选择的节点
返回值: 无
-------------------------------------------------------------------------------}
procedure AddTreeNode(ClientDataSet:TClientDataSet;TreeView: TTreeView; bj: boolean = false);
{-------------------------------------------------------------------------------
过程名: DelTree
说明: 删除节点(包括删除本节点下的所有子节点)
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView;
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure DelTree(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: Treechange
说明: 在树中选择了一个节点,将数据库的游标移动到所选择的节点所对应记录
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; node: TTreenode
参数说明: ClientDataSet:相关联的客户端数据集; TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure Treechange(ClientDataSet:TClientDataSet; node: TTreenode);
{-------------------------------------------------------------------------------
过程名: Treeedit
说明: 树中的节点内容已经作了修改,将所修改的内容更新回数据库
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; text: string
参数说明: ClientDataSet:相关联的数据库; text: string
返回值: 无
-------------------------------------------------------------------------------}
procedure Treeedit(ClientDataSet:TClientDataSet; text: string);
{-------------------------------------------------------------------------------
过程名: treeselect
说明: 数据库中的游标已经移动,将焦点移到树中对应的节点
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView
参数说明: ClientDataSet:TClientDataSet; 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure TreeSelect(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
函数名: TreeFind
说明: 找出给定的内容,并移动数据库中的游标,同时将焦点移到树中对应的节点
作者: DLS
日期: 2006.08.19
参数: TreeView: TTreeView; text: string
参数说明: TreeView: 所使用的树 text: 要查找的内容
返回值: True:找到 False:找不到
-------------------------------------------------------------------------------}
function TreeFind(TreeView: TTreeView; text: string): boolean;
end;
var
Formsdltree: TFormsdltree;
List: TStringList; //用于记录各个id及其在树中所对应的节点,从而实现快速查找
serial_number:integer;//用于记录ID标示
implementation
uses dmpas;
procedure TFormsdltree.BtnMakeTreeClick(Sender: TObject);
begin
MakeTree(dm.ClientDataSet1.ProviderName,TreeView1);
end;
procedure TFormsdltree.MakeTree(ClientDataSetName: string; TreeView: TTreeView);
begin
TreeView.Items.BeginUpdate;
list.Clear;
TreeView.items.clear;
//TreeView.Items.Clear;
//list.Clear;
List.Sorted := True;
with dm.ClientDataSet1 do
begin
First;
while not Eof do
begin
addtreenode(dm.ClientDataSet1,TreeView); //依次增加所有的节点
Next;
end;
end;
TreeView.Items.EndUpdate;
if treeview.Items.Count < 1 then exit;
treeview.Select(treeview.Items.Item[0]);
treeview.SetFocus;
end;
procedure TFormsdltree.addtreenode(ClientDataSet:TClientDataSet;TreeView: TTreeView; bj: boolean = false);
var
index: integer;
Node: TTreeNode;
begin
if ClientDataSet.FieldByName('City_Infor_Privence_ID').AsInteger = 0 then
Node := TreeView.Items.AddChildObject(nil,
ClientDataSet.FieldByName('City_Infor_name').AsString,ClientDataSet.GetBookmark)
//增加节点,并将本节点所对应的记录标签数据放到节点所提供的附加数据中
else
begin
Index := List.IndexOf(ClientDataSet.FieldByName('City_Infor_Privence_ID').AsString);
Node := TreeView.Items.AddChildObjectFirst(TTreeNode(List.Objects[Index]),
ClientDataSet.FieldByName('City_Infor_name').AsString, ClientDataSet.GetBookmark);
//增加子节点,并将本节点所对应的记录标签数据放到节点所提供的附加数据中
end;
//增加当前节点的信息到列表中,以实现在列表中快速查找节点的功能。
List.AddObject(ClientDataSet.FieldByName('City_Infor_ID').AsString, Node);
if bj then
begin
treeview.Select(node);
treeview.SetFocus;
end;
end;
procedure TFormsdltree.deltree(ClientDataSet:TClientDataSet; TreeView: TTreeView);
var
node: TTreenode;
//删除当前选择的节点下的所有节点(不删除当前选择的节点)
procedure delnode(node: TTreenode);
var
i: integer;
childnode: TTreenode;
begin
for i := 0 to node.Count - 1 do
begin
childnode := node.Item[i]; //取当前节点下的所有节点
ClientDataSet.GotoBookmark(childnode.Data); //移到节点所对应的记录
list.Delete(list.IndexOf(ClientDataSet.FieldByName('City_Infor_ID').AsString)); //删除列表中的数据
ClientDataSet.Delete; //删除对应的记录
if node.HasChildren then delnode(childnode); //有子节点则递归直到所有的数据删除完毕
end;
end;
{另一方法:
用一个递归:
procedure doSearch(tn: TTreeNode);
var i: ingeger;
begin
if tn.HasChildren then
begin
for i := tn.Count -1 downto 0 do doSearch(tn[i]);
end
else
begin
//这里是你对每个节电要做的事情
end;
end;}
begin
node := treeview.Selected;
if node = nil then exit;
//删除当前选择的节点下的所有节点(不删除当前选择的节点)
delnode(node);
//删除当前选择的节点
ClientDataSet.GotoBookmark(node.Data);
list.Delete(list.IndexOf(ClientDataSet.FieldByName('City_Infor_ID').AsString));
ClientDataSet.Delete;
node.Delete;
TreeView.SetFocus;
end;
procedure TFormsdltree.AddChildNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
var
id: integer;
begin
id := ClientDataSet.FieldByName('City_Infor_ID').AsInteger; //记下当前的节点编号,作为子节点的父点
ClientDataSet.Append;
ClientDataSet.FieldByName('City_Infor_Privence_ID').AsInteger := id; //新增加的子节点的父节点编号即为id
ClientDataSet.FieldByName('City_Infor_name').AsString := '新子节点';
serial_number := serial_number+1;
ClientDataSet.FieldByName('City_Infor_ID').AsInteger :=serial_number;
ClientDataSet.post;
addtreenode(ClientDataSet, treeview, true);
end;
procedure TFormsdltree.AddNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
var
Currentid: integer;
begin
Currentid := ClientDataSet.FieldByName('City_Infor_ID').AsInteger; //记下当前节点的节点编号
ClientDataSet.Append;
ClientDataSet.FieldByName('City_Infor_Privence_ID').AsInteger := Currentid; //新增加的子节点的父节点编号即为Currentid
ClientDataSet.FieldByName('City_Infor_name').AsString := '新节点';
serial_number := serial_number+1;
ClientDataSet.FieldByName('City_Infor_ID').AsInteger :=serial_number ;
ClientDataSet.Post;
addtreenode(ClientDataSet, treeview, true);
end;
procedure TFormsdltree.Treechange(ClientDataSet:TClientDataSet; node: TTreenode);
begin
ClientDataSet.GotoBookmark(node.Data);
end;
procedure TFormsdltree.TreeEdit(ClientDataSet: TClientDataSet; text: string);
begin
ClientDataSet.Edit;
ClientDataSet.FieldByName('City_Infor_name').AsString := text;
ClientDataSet.post;
end;
procedure TFormsdltree.treeselect(ClientDataSet: TClientDataSet; TreeView: TTreeView);
var
index: integer;
Node: TTreeNode;
begin
Index := List.IndexOf(ClientDataSet.FieldByName('City_Infor_ID').AsString);
Node := TTreeNode(List.Objects[Index]);
treeview.Selected := Node;
treeview.SetFocus;
end;
function TFormsdltree.TreeFind(TreeView: TTreeView; text: string): boolean;
var
i: integer;
begin
Result := false;
for i := 0 to treeview.Items.Count - 1 do
begin
if treeview.Items.Item[i].Text = text then
begin
treeview.Select(treeview.Items.Item[i]);
treeview.SetFocus;
Result := true;
exit;
end;
end;
end;
procedure TFormsdltree.FormCreate(Sender: TObject);
begin
list:=TStringList.Create ;
with dm.ClientDataSet1 do
begin
if Active then Active:=False;
ProviderName:='DSP_City_Infor';
Open;
Last;
serial_number:=dm.ClientDataSet1.FieldValues['City_Infor_ID'];
end;
end;
procedure TFormsdltree.FormDestroy(Sender: TObject);
begin
list.Free;
dm.ClientDataSet1.ApplyUpdates(-1);//更改用户数据集
end;
procedure TFormsdltree.BtnAddNodeClick(Sender: TObject);
begin
addnode(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.BtnAddChildNodeClick(Sender: TObject);
begin
addchildnode(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.BtnDeleteTreeClick(Sender: TObject);
begin
deltree(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.DBGrid1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
treeselect(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
treechange(dm.ClientDataSet1,node);
end;
procedure TFormsdltree.TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
begin
treeedit(dm.ClientDataSet1,s);
end;
procedure TFormsdltree.BtnFindClick(Sender: TObject);
begin
if not TreeFind(treeview1,edFindText.Text) then
MessageBox(0,'没有找到','信息',mb_ok);
end;
end.
unit sdlformtree;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, ExtCtrls, ComCtrls,DBClient, DBCtrls;
type
TFormsdltree = class(TForm)
TreeView1: TTreeView;
Panel14: TPanel;
BtnMakeTree: TButton;
BtnAddChildNode: TButton;
BtnAddNode: TButton;
BtnDeleteTree: TButton;
BtnFind: TButton;
EdFindText: TEdit;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
procedure BtnMakeTreeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BtnAddNodeClick(Sender: TObject);
procedure BtnAddChildNodeClick(Sender: TObject);
procedure BtnDeleteTreeClick(Sender: TObject);
procedure DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
procedure BtnFindClick(Sender: TObject);
private
public
//==============================================================================
// 本单元实现了TreeView与数据的关联,其各项要求如下:
//
// 数据库这里采用了Interbase表,使用三层技术编程的方法,表中的字段要
// 有id,pid,caption三个。
// id: 为自增字段,用于表示节点的编号。
// caption: 用来表示在树中所要显示的内容。
// pid: 用来表示当前节点的父节点。
//在这个城市地区例子中,有 city_infor_ID、city_infor_Name和city_infor_privence_ID
//三个字段。
//==============================================================================
{-------------------------------------------------------------------------------
过程名: MakeTree
说明: 创建树
作者: DLS
日期: 2006.08.19
参数: ClientDataSetName: string; TreeView: TTreeView
参数说明: ClientDataSetName: 对应的客户数据集名; TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure MakeTree(ClientDataSetName: string; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: AddNode
说明: 增加树的节点
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure AddNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: AddChildNode
说明: 增加树的子节点
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure AddChildNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: AddTreeNode
说明: 增加节点(内部使用的过程)
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView; bj: boolean = false
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树;
bj:是否将焦点移到当前选择的节点
返回值: 无
-------------------------------------------------------------------------------}
procedure AddTreeNode(ClientDataSet:TClientDataSet;TreeView: TTreeView; bj: boolean = false);
{-------------------------------------------------------------------------------
过程名: DelTree
说明: 删除节点(包括删除本节点下的所有子节点)
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView;
参数说明: ClientDataSet:相关联的客户端数据集;TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure DelTree(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
过程名: Treechange
说明: 在树中选择了一个节点,将数据库的游标移动到所选择的节点所对应记录
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; node: TTreenode
参数说明: ClientDataSet:相关联的客户端数据集; TreeView: 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure Treechange(ClientDataSet:TClientDataSet; node: TTreenode);
{-------------------------------------------------------------------------------
过程名: Treeedit
说明: 树中的节点内容已经作了修改,将所修改的内容更新回数据库
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; text: string
参数说明: ClientDataSet:相关联的数据库; text: string
返回值: 无
-------------------------------------------------------------------------------}
procedure Treeedit(ClientDataSet:TClientDataSet; text: string);
{-------------------------------------------------------------------------------
过程名: treeselect
说明: 数据库中的游标已经移动,将焦点移到树中对应的节点
作者: DLS
日期: 2006.08.19
参数: ClientDataSet:TClientDataSet; TreeView: TTreeView
参数说明: ClientDataSet:TClientDataSet; 所使用的树
返回值: 无
-------------------------------------------------------------------------------}
procedure TreeSelect(ClientDataSet:TClientDataSet; TreeView: TTreeView);
{-------------------------------------------------------------------------------
函数名: TreeFind
说明: 找出给定的内容,并移动数据库中的游标,同时将焦点移到树中对应的节点
作者: DLS
日期: 2006.08.19
参数: TreeView: TTreeView; text: string
参数说明: TreeView: 所使用的树 text: 要查找的内容
返回值: True:找到 False:找不到
-------------------------------------------------------------------------------}
function TreeFind(TreeView: TTreeView; text: string): boolean;
end;
var
Formsdltree: TFormsdltree;
List: TStringList; //用于记录各个id及其在树中所对应的节点,从而实现快速查找
serial_number:integer;//用于记录ID标示
implementation
uses dmpas;
procedure TFormsdltree.BtnMakeTreeClick(Sender: TObject);
begin
MakeTree(dm.ClientDataSet1.ProviderName,TreeView1);
end;
procedure TFormsdltree.MakeTree(ClientDataSetName: string; TreeView: TTreeView);
begin
TreeView.Items.BeginUpdate;
list.Clear;
TreeView.items.clear;
//TreeView.Items.Clear;
//list.Clear;
List.Sorted := True;
with dm.ClientDataSet1 do
begin
First;
while not Eof do
begin
addtreenode(dm.ClientDataSet1,TreeView); //依次增加所有的节点
Next;
end;
end;
TreeView.Items.EndUpdate;
if treeview.Items.Count < 1 then exit;
treeview.Select(treeview.Items.Item[0]);
treeview.SetFocus;
end;
procedure TFormsdltree.addtreenode(ClientDataSet:TClientDataSet;TreeView: TTreeView; bj: boolean = false);
var
index: integer;
Node: TTreeNode;
begin
if ClientDataSet.FieldByName('City_Infor_Privence_ID').AsInteger = 0 then
Node := TreeView.Items.AddChildObject(nil,
ClientDataSet.FieldByName('City_Infor_name').AsString,ClientDataSet.GetBookmark)
//增加节点,并将本节点所对应的记录标签数据放到节点所提供的附加数据中
else
begin
Index := List.IndexOf(ClientDataSet.FieldByName('City_Infor_Privence_ID').AsString);
Node := TreeView.Items.AddChildObjectFirst(TTreeNode(List.Objects[Index]),
ClientDataSet.FieldByName('City_Infor_name').AsString, ClientDataSet.GetBookmark);
//增加子节点,并将本节点所对应的记录标签数据放到节点所提供的附加数据中
end;
//增加当前节点的信息到列表中,以实现在列表中快速查找节点的功能。
List.AddObject(ClientDataSet.FieldByName('City_Infor_ID').AsString, Node);
if bj then
begin
treeview.Select(node);
treeview.SetFocus;
end;
end;
procedure TFormsdltree.deltree(ClientDataSet:TClientDataSet; TreeView: TTreeView);
var
node: TTreenode;
//删除当前选择的节点下的所有节点(不删除当前选择的节点)
procedure delnode(node: TTreenode);
var
i: integer;
childnode: TTreenode;
begin
for i := 0 to node.Count - 1 do
begin
childnode := node.Item[i]; //取当前节点下的所有节点
ClientDataSet.GotoBookmark(childnode.Data); //移到节点所对应的记录
list.Delete(list.IndexOf(ClientDataSet.FieldByName('City_Infor_ID').AsString)); //删除列表中的数据
ClientDataSet.Delete; //删除对应的记录
if node.HasChildren then delnode(childnode); //有子节点则递归直到所有的数据删除完毕
end;
end;
{另一方法:
用一个递归:
procedure doSearch(tn: TTreeNode);
var i: ingeger;
begin
if tn.HasChildren then
begin
for i := tn.Count -1 downto 0 do doSearch(tn[i]);
end
else
begin
//这里是你对每个节电要做的事情
end;
end;}
begin
node := treeview.Selected;
if node = nil then exit;
//删除当前选择的节点下的所有节点(不删除当前选择的节点)
delnode(node);
//删除当前选择的节点
ClientDataSet.GotoBookmark(node.Data);
list.Delete(list.IndexOf(ClientDataSet.FieldByName('City_Infor_ID').AsString));
ClientDataSet.Delete;
node.Delete;
TreeView.SetFocus;
end;
procedure TFormsdltree.AddChildNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
var
id: integer;
begin
id := ClientDataSet.FieldByName('City_Infor_ID').AsInteger; //记下当前的节点编号,作为子节点的父点
ClientDataSet.Append;
ClientDataSet.FieldByName('City_Infor_Privence_ID').AsInteger := id; //新增加的子节点的父节点编号即为id
ClientDataSet.FieldByName('City_Infor_name').AsString := '新子节点';
serial_number := serial_number+1;
ClientDataSet.FieldByName('City_Infor_ID').AsInteger :=serial_number;
ClientDataSet.post;
addtreenode(ClientDataSet, treeview, true);
end;
procedure TFormsdltree.AddNode(ClientDataSet:TClientDataSet; TreeView: TTreeView);
var
Currentid: integer;
begin
Currentid := ClientDataSet.FieldByName('City_Infor_ID').AsInteger; //记下当前节点的节点编号
ClientDataSet.Append;
ClientDataSet.FieldByName('City_Infor_Privence_ID').AsInteger := Currentid; //新增加的子节点的父节点编号即为Currentid
ClientDataSet.FieldByName('City_Infor_name').AsString := '新节点';
serial_number := serial_number+1;
ClientDataSet.FieldByName('City_Infor_ID').AsInteger :=serial_number ;
ClientDataSet.Post;
addtreenode(ClientDataSet, treeview, true);
end;
procedure TFormsdltree.Treechange(ClientDataSet:TClientDataSet; node: TTreenode);
begin
ClientDataSet.GotoBookmark(node.Data);
end;
procedure TFormsdltree.TreeEdit(ClientDataSet: TClientDataSet; text: string);
begin
ClientDataSet.Edit;
ClientDataSet.FieldByName('City_Infor_name').AsString := text;
ClientDataSet.post;
end;
procedure TFormsdltree.treeselect(ClientDataSet: TClientDataSet; TreeView: TTreeView);
var
index: integer;
Node: TTreeNode;
begin
Index := List.IndexOf(ClientDataSet.FieldByName('City_Infor_ID').AsString);
Node := TTreeNode(List.Objects[Index]);
treeview.Selected := Node;
treeview.SetFocus;
end;
function TFormsdltree.TreeFind(TreeView: TTreeView; text: string): boolean;
var
i: integer;
begin
Result := false;
for i := 0 to treeview.Items.Count - 1 do
begin
if treeview.Items.Item[i].Text = text then
begin
treeview.Select(treeview.Items.Item[i]);
treeview.SetFocus;
Result := true;
exit;
end;
end;
end;
procedure TFormsdltree.FormCreate(Sender: TObject);
begin
list:=TStringList.Create ;
with dm.ClientDataSet1 do
begin
if Active then Active:=False;
ProviderName:='DSP_City_Infor';
Open;
Last;
serial_number:=dm.ClientDataSet1.FieldValues['City_Infor_ID'];
end;
end;
procedure TFormsdltree.FormDestroy(Sender: TObject);
begin
list.Free;
dm.ClientDataSet1.ApplyUpdates(-1);//更改用户数据集
end;
procedure TFormsdltree.BtnAddNodeClick(Sender: TObject);
begin
addnode(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.BtnAddChildNodeClick(Sender: TObject);
begin
addchildnode(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.BtnDeleteTreeClick(Sender: TObject);
begin
deltree(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.DBGrid1MouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
treeselect(dm.ClientDataSet1,TreeView1);
end;
procedure TFormsdltree.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
treechange(dm.ClientDataSet1,node);
end;
procedure TFormsdltree.TreeView1Edited(Sender: TObject; Node: TTreeNode;
var S: String);
begin
treeedit(dm.ClientDataSet1,s);
end;
procedure TFormsdltree.BtnFindClick(Sender: TObject);
begin
if not TreeFind(treeview1,edFindText.Text) then
MessageBox(0,'没有找到','信息',mb_ok);
end;
end.
展开全部
首先确定三个表的关系,如果是简单的 No 相等关系,那么只要一个SQL语句就行了:
select a.No,a.Name,c.Ppo,a.Date,b.Serial from a,b,c
where a.No=b.No and a.No=c.No
这样就好了
select a.No,a.Name,c.Ppo,a.Date,b.Serial from a,b,c
where a.No=b.No and a.No=c.No
这样就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单的办法就是插入<script src="**.asp" type="text/javascript"></script>
asp文件中写入:
Response.Write "document.write('"&sql&"');"
asp文件中写入:
Response.Write "document.write('"&sql&"');"
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只能分几个控件来实现,点击父节点,就在另个控件,列出所有的子节点信息。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用DXDBGRID的吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询