有关treeview控件的使用问题(100分)

  • 主题发起人 fayuange
  • 开始时间
F

fayuange

Unregistered / Unconfirmed
GUEST, unregistred user!
经常看到有些软件中关于“部门增加”的问题,我用INTERBASE数据库建一"depart"表,表结构为
id(部门编号,最多三层编号,每层编号固定为2位数字),name(部门名称),如:
id name
01 部门甲
0101 部门甲1
02 部门乙
请问,用TREEVIEW控件如何按编号层次显示以上部门名称,怎样通过选定一个部门名称实现
该部门的同级部门增加或下级部门增加?
在线等候,期待大侠的指点。
 
建表时建成主从表不就行了吗;用你的表只能进行多次循环查询了
 
方法不对头:
应该两张表:
表1:部门关系
部门ID 上级部门ID
表2:部门表
部门ID 部门名称 。。。。

之后就简单了
 
随手写来,大致如下:

var
L:TStrings;
s:String;
n:integer;
begin
table1.indexname:='aaa';
table1.indexFieldnames:='id';
table1.first;

L:=TStringList.Create;
while not(table1.eof()) do
begin
n:=length(trim(table1.fields['id'].asstring));
n:=(n div 2)-1;
s:=stringofchar(8,n)+trim(table1.fields['name'].asstring)
table1.next;
end;
L.saveToFile('Temp.txt');
L.Free;
treeview1.loadfromfile('Temp.txt');
end;
 
我做过一个,Delphi+MySQL
代码管理,可以给你看看,赫赫
先调第一级,点中第一级的节点,调相应的第二级,以此类推
 
我当时是这样考虑的,部门编号固定(或为2位数字,或为4位,或为6位),若部门编号为2位,
则TREEVIEW中显示为一级目录,若为4位则显示为二级,其上级部门为该部门编号的前二位数字代表的
部门名称,以此类推,因此我觉得可通过某种方法实现该功能,没必要再建部门关系表,请指教。

JSXJD朋友的代码我觉得不行,并且在DELPHI6+INTERBASE下也编译不过。
TWOS朋友,能把您的代码发给我一份吗?
我的E_MAIL:fayuange@sina.com
 
下面的我已经调试过了:

procedure TForm1.Button1Click(Sender: TObject);
var
L:TStrings;
s:String;
n:integer;
begin
table1.indexname:='aaa';
table1.indexFieldnames:='id';
table1.first;

L:=TStringList.Create;
while not(table1.eof) do
begin
n:=length(trim(table1.fieldbyName('id').asstring));
n:=(n div 2)-1;
s:=stringofchar(char(8),n)+trim(table1.fieldbyName('name').asstring);
table1.next;
end;
L.saveToFile('Temp.txt');
L.Free;
treeview1.loadfromfile('Temp.txt');
end;
 
接受答案了.
 
顶部