有没有什么VCL树控件和数据库联系紧密的?

dingdangy 2003-09-09 12:01:28
我有几十个表,然后关联起来后可以生成一个目录树表,但是层次很多且数据量有点大,一般层次在6层,最小的目录数目大概在千条多。如果自己用treeview编程实现太烦了。不知道有没有这样的树控件直接和数据库可以绑定,按照一定的数据格式自动生成的?
...全文
3 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingdangy 2003-09-09
madyak(无天) 非常感谢,你有没有使用的经验?可以交流一下。
回复
Drate 2003-09-09
I have a table1 with a field 'treenode'.Please teach me How to read all items (record) to
"Addchild" to treewiew, start from Treeview1.items[0].
Using ADOTable1


any dataTable using same Fuction

some source for if u need:

ID FolderID and ParentID is Table's field, save node data

and must create index for it.

FolderTable is my database table.

procedure TBook.FillFolderTreeView;

// using recursion to fill Treeview
// u need this child method

procedure FillTreeNode(TreeNode: TTreeNode);
var
I, FolderID: Integer;
Node: TTreeNode;
begin
FolderID := Integer(TreeNode.Data);

FolderTable.Filter := 'ParentID=' + IntToStr(FolderID);
FolderTable.Filtered := True;
FolderTable.First;

for I := 0 to FolderTable.RecordCount - 1 do
begin
Node := TreeView.Items.AddChild(
TreeNode, FolderTable.FieldByName('Name').AsString);

Node.Data := Pointer(FolderTable.FieldByName('ID').AsInteger);
Node.SelectedIndex := 1;
FolderTable.Next ;
end;

for I := 0 to TreeNode.Count - 1 do
begin
FillTreeNode(TreeNode.Item[I]);
end;
end;

begin
//initialize TreeView
TreeView.Items.BeginUpdate ;
TreeView.Items.Clear ;

//Fill Node and Expand all nod
FillTreeNode(TreeView.Items[0]);
TreeView.FullExpand;
TreeView.Items.EndUpdate ;

TreeView.Items[1].Selected := True;
end;
Comment from leeon Date: 05/05/2003 10:54AM PDT
this is a new folder's method.

u maybe know how to do it.

read this source and i post source later,

Inputform is writing strings form.

don't care that.

procedure TBook.NewFolderExecute(Sender: TObject);
var
ParentID: Integer;
FolderName: String;
TreeNode: TTreeNode;
begin
if TreeView.Selected = nil then Exit;
ParentID := Integer(TreeView.Selected.Data);

if ShowInputForm(FolderName, SNewFolder, SFolderName) then
begin
FolderTable.Filtered := False;
FolderTable.Append;
FolderTable.FieldByName('ParentID').AsInteger := ParentID;
FolderTable.FieldByName('Name').AsString := FolderName;
FolderTable.Post ;

TreeNode := TreeView.Items.AddChild(TreeView.Selected, FolderName);
TreeNode.Data := Pointer(FolderTable.FieldByName('ID').AsInteger);
TreeNode.SelectedIndex := 1;
TreeNode.MakeVisible ;
TreeNode.Selected := True;
end;
end;
Comment from z27 Date: 05/05/2003 05:27PM PDT
Thank you very much!
Comment from leeon Date: 05/05/2003 07:26PM PDT
:) u r welcome.

here is delete folder method

you'd better read this careful

//cardtable is File table, FolderTable save it's data

procedure TBook.DeleteFolderExecute(Sender: TObject);
var
TreeNode: TTreeNode;
FolderID, R: Integer;
begin
if TreeView.Selected = nil then Exit;
TreeNode := TreeView.Selected ;
if TreeNode.AbsoluteIndex in [0,1] then Exit;

R := MessageBox(
Application.Handle,
PChar(SQueryDeleteFolder),
PChar('Are you sure to delete the folder?'),
36);
if R = ID_NO then Exit;

FolderID := Integer(TreeNode.Data);
FolderTable.Filtered := False;
FolderTable.IndexName := '';

if FolderTable.FindKey([FolderID]) then
begin
FolderTable.Delete ;

CardTable.Filtered := False;
CardTable.IndexName := 'ByFolderID';
while CardTable.FindKey([FolderID]) do
begin
CardTable.Delete;
end;

TreeNode.Delete ;
end;
end;
回复
madyak 2003-09-09
可以试试Devexpress DBTree控件
ftp://202.117.210.28/file/dbtreed7.rar 是D7的版本
ftp://202.117.210.28/file/dbtree13.rar 是其它的版本
回复
dingdangy 2003-09-09
不知道有谁用过 9Rays DBFlyTreeViewPro Suite.v7.3.Delphi.BCB.Full 这个没有?
回复
dingdangy 2003-09-09
哦?我先看看。但是DBGrid用来做目录树我还是第一次听说。有demo没有?
回复
Stack 2003-09-09
dev express 的 DBGrid这一组里面有(好像叫DxDbgrid), 界面很棒, 功能巨强
回复
dingdangy 2003-09-09
我以前见过从特定格式的配置文件,例如一个INI文件读取信息,自动建立目录树的控件。现在急需有一个可以直接和数据库关联的这样一个类似的控件。希望大家帮帮忙。谢谢了!
回复
发动态
发帖子
数据库相关
创建于2007-08-02

2440

社区成员

Delphi 数据库相关
申请成为版主
社区公告
暂无公告