procedure TForm1.Button1Click(Sender: TObject); var SearchRec : TSearchRec; Path : String; Attr : integer; Found : integer; begin Path := 'c:\*.*'; Attr := faAnyFile; Found := FindFirst(Path, Attr, SearchRec); while Found = 0 do begin ListView1.Items.Add; ListView1.Items[ListView1.Items.Count-1].Caption := (SearchRec.Name); Found := FindNext(SearchRec); end; FindClose(SearchRec); end; 如果要删除全部:listview.items.clear 如果要删除当前所选行:listview1.selected.delete 如果要删除指定行.listview1.items.item[i].delete在做增加删除的时候可以同时进行数据库的删除
曾经做过一个TreeView连数据库的例程,要的话请留下E-MAIL,最好是发短消息给我.
procedure TForm1.AddTreeNode(TV:TTreeView); var sFatherTxt,sNodetxt,sCode:string; cPrice:Currency; iChildnum,i:integer; ttTreeNode:TTreeNode; begin
ttTreeNode:=TV.Selected; if ttTreeNode.Level=2 then begin MessageDlg('请选择上一层节点!',mtInformation,[mbyes],0); Exit; end; // 限定为两层节点 sInputString:=InputBox('输入框','请输入项目名称!',''); // 输入框。 //sFatherTxt:=ttTreeNode.Parent.Text; sNodetxt:=ttTreeNode.Text; //获得选中结点的文本。 if ttTreeNode.Level=0 then //select the root node begin iChildnum:=ttTreeNode.Count; //get the number of the child node. if iChildnum<9 then sCode:='0'+inttostr(iChildnum+1); if iChildnum>9 then sCode:=inttostr(iChildnum+1); end else begin for i:=1 to length(sNodetxt)do begin if sNodetxt[i]='-' then sCode:=copy(sNodetxt,1,i-1); end; if ttTreeNode.HasChildren then begin iChildnum:=ttTreeNode.Count; //get the number of the child node. if iChildnum<9 then sCode:=sCode+'0'+IntToStr(iChildnum+1); if iChildnum>9 then sCode:=sCode+IntToStr(iChildnum+1); end else begin sCode:=sCode+'01'; end; end; //获得要插入项目的代码 for i:=1 to length(sNodetxt) do begin if sNodetxt[i]='-' then sFatherTxt:=copy(sNodetxt,i+1,length(sNodetxt)-i+1); end; //获取父亲文本 TV.Items.AddChild(ttTreeNode,sCode+'-'+sInputString); //增加节点 //产生SQL更新数据库 sSQLStr:='Insert sTableName values()'; With query1 do begin sql.clear; sql.add(Trim(sSQLStr)); ExecSQL; end;end;
var
SearchRec : TSearchRec;
Path : String;
Attr : integer;
Found : integer;
begin
Path := 'c:\*.*';
Attr := faAnyFile;
Found := FindFirst(Path, Attr, SearchRec);
while Found = 0 do
begin
ListView1.Items.Add;
ListView1.Items[ListView1.Items.Count-1].Caption := (SearchRec.Name);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
如果要删除全部:listview.items.clear
如果要删除当前所选行:listview1.selected.delete
如果要删除指定行.listview1.items.item[i].delete在做增加删除的时候可以同时进行数据库的删除
var
sFatherTxt,sNodetxt,sCode:string;
cPrice:Currency;
iChildnum,i:integer;
ttTreeNode:TTreeNode;
begin
ttTreeNode:=TV.Selected; if ttTreeNode.Level=2 then
begin
MessageDlg('请选择上一层节点!',mtInformation,[mbyes],0);
Exit;
end;
// 限定为两层节点 sInputString:=InputBox('输入框','请输入项目名称!','');
// 输入框。 //sFatherTxt:=ttTreeNode.Parent.Text;
sNodetxt:=ttTreeNode.Text; //获得选中结点的文本。
if ttTreeNode.Level=0 then //select the root node
begin
iChildnum:=ttTreeNode.Count; //get the number of the child node.
if iChildnum<9 then
sCode:='0'+inttostr(iChildnum+1);
if iChildnum>9 then
sCode:=inttostr(iChildnum+1);
end
else
begin
for i:=1 to length(sNodetxt)do
begin
if sNodetxt[i]='-' then
sCode:=copy(sNodetxt,1,i-1);
end;
if ttTreeNode.HasChildren then
begin
iChildnum:=ttTreeNode.Count; //get the number of the child node.
if iChildnum<9 then
sCode:=sCode+'0'+IntToStr(iChildnum+1);
if iChildnum>9 then
sCode:=sCode+IntToStr(iChildnum+1);
end
else
begin
sCode:=sCode+'01';
end;
end; //获得要插入项目的代码 for i:=1 to length(sNodetxt) do
begin
if sNodetxt[i]='-' then
sFatherTxt:=copy(sNodetxt,i+1,length(sNodetxt)-i+1);
end;
//获取父亲文本 TV.Items.AddChild(ttTreeNode,sCode+'-'+sInputString);
//增加节点 //产生SQL更新数据库
sSQLStr:='Insert sTableName values()';
With query1 do
begin
sql.clear;
sql.add(Trim(sSQLStr));
ExecSQL;
end;end;