关于TREEVIEW(50分)

  • 主题发起人 主题发起人 茄子
  • 开始时间 开始时间

茄子

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么才能把多层记录添加到TREEVIEW中啊?
急!!!
 
//我财务软件的代码,仔细看,FormatStr为代码格式(如322222,最大6级,每级最大5位)
procedure RefreshTview(FormatStr:String;CodeStr:String;TmpTreeview:TTreeView);
var
TmpSql,NodeTxt,TmpCode:String;
Level:Integer;
MyQuery:TADOQuery;
TmpNode:Array [0..6] of TTreenode;
begin
Screen.Cursor:=crHourGlass;
Try
MyQuery:=TADOQuery.Create(Application.Owner);
TmpTreeview.Enabled:=True;
TmpTreeview.Items.Clear;
TmpSql:='Select * from DataCode Where DateCodeID='''+CodeStr+''' and IfCancel=False Order By DateCode';
FindRecordInDataDB(MyQuery,TmpSql);
MyQuery.First;
while not MyQuery.Eof do
begin
NodeTxt:=MyQuery.FieldByName('DateCode').AsString+'-'+MyQuery.FieldByName('DateName').AsString;
TmpCode:=MyQuery.FieldByName('DateCode').AsString;
Level:=GetNodeLevel(FormatStr,TmpCode);
if Level=1 then
begin
TmpNode[Level]:=TmpTreeview.Items.Add(TmpTreeview.TopItem,NodeTxt);
TmpNode[Level].ImageIndex:=1;
TmpNode[Level].SelectedIndex:=1;
end
else
begin
TmpNode[Level]:=TmpTreeview.Items.AddChild(TmpNode[level-1],NodeTxt);
TmpNode[Level].ImageIndex:=1;
TmpNode[Level].SelectedIndex:=1;
end;
MyQuery.Next;
end;
Finally
MyQuery.Free;
end;
Screen.Cursor:=crDefault;
end;

procedure RefreshTview(FormatStr:String;CodeStr:String;TmpTreeview:TTreeView);
var
TmpSql,NodeTxt,TmpCode:String;
Level:Integer;
MyQuery:TADOQuery;
TmpNode:Array [0..6] of TTreenode;
begin
Screen.Cursor:=crHourGlass;
Try
MyQuery:=TADOQuery.Create(Application.Owner);
TmpTreeview.Enabled:=True;
TmpTreeview.Items.Clear;
TmpSql:='Select * from DataCode Where DateCodeID='''+CodeStr+''' and IfCancel=False Order By DateCode';
FindRecordInDataDB(MyQuery,TmpSql);
MyQuery.First;
while not MyQuery.Eof do
begin
NodeTxt:=MyQuery.FieldByName('DateCode').AsString+'-'+MyQuery.FieldByName('DateName').AsString;
TmpCode:=MyQuery.FieldByName('DateCode').AsString;
Level:=GetNodeLevel(FormatStr,TmpCode);
if Level=1 then
begin
TmpNode[Level]:=TmpTreeview.Items.Add(TmpTreeview.TopItem,NodeTxt);
TmpNode[Level].ImageIndex:=1;
TmpNode[Level].SelectedIndex:=1;
end
else
begin
TmpNode[Level]:=TmpTreeview.Items.AddChild(TmpNode[level-1],NodeTxt);
TmpNode[Level].ImageIndex:=1;
TmpNode[Level].SelectedIndex:=1;
end;
MyQuery.Next;
end;
Finally
MyQuery.Free;
end;
Screen.Cursor:=crDefault;
end;
 
看看以下代码:
2. 树状年历
procedure TForm1.Button1Click(Sender: TObject);
var
beginYear,endYear:integer;
y,m,day:word;
d:tdateTime;
nY,nM:TTreeNode;
begin
beginYear:=2002;
endYear:=2004;
d:=strtodate(inttostr(beginYear)+'-1-1');
decodeDate(d,y,m,day);
ny:=nil;
nm:=nil;
while y<=endYear do
begin
if (m=1) and (day=1) then
ny:=treeview1.Items.Add(nil,FormatDateTime('yyyy"年',d));
if (day=1) then
nM:=treeview1.Items.AddChild(ny,FormatDateTime('mm"月',d));
treeview1.Items.AddChild(nm,FormatDateTime('dd"日',d));
d:=d+1;
decodeDate(d,y,m,day);
end;
end;
 
谢谢各位了!
 
如何进行维护?
 
后退
顶部