请问在Listview1使用中,第一栏是caption这个用作[序号]的生成,
caption:=IntToStr(Listview1.Items.Count);
出现效果如下:
====================================
序号 | 电话号码 | 日期
====================================
01 | 13800138000 | 2010-09-04 15:22:24
10 | 13800138000 | 2010-09-04 15:22:24 //奇怪,为什么会小学教师实习报告 在这里而不是在09之后呢??如何才可以排列在09后面呢???
02 | 13800138000 | 2010-09-04 15:22:24
03 | 13800138000 | 2010-09-04 15:22:24
04 | 13800138000 | 2010-09-04 15:22:24
05 | 13800138000 | 2010-09-04 15:22:24
06 | 13800138000 | 2010-09-04 15:22:24
07 | 13800138000 | 2010-09-04 15:22:24
08 | 13800138000 | 2010-09-04 15:22:24
09 | 13800138000 | 2010-09-04 15:22:24
...
上面记录被加到Listview1之后,假如删除其中几条记录将如下情况:
====================================
序号 | 电话号码 | 日期
====================================
10 | 13800138000 | 2010-09-04 15:22:24
02 | 13800138000 | 2010-09-04 15:22:24
04 | 13800138000 | 2010-09-04 15:22:24
06 | 13800138000 | 2010-09-04 15:22:24
07 | 13800138000 | 2010-09-04 15:22:24
08 | 13800138000 | 2010-09-04 15:22:24
09 | 13800138000 | 2010-09-04 15:22:24
...
把1、3、5几条记录删除了,序号出现断号,不连贯了~~~
请问在删除后在[序号]里如何获得01、02、03、04、05、06...连贯编号呢?
不清楚你如何新增项,按我下面代码不会出现那情形,删除后序号重排即可连贯:
Delphi/Pascal code123456789101112131415161718192021222324252627282930313233343536373839 procedure TForm1.FormCreate(Sender: TObject); var i:integer; s:string; begin for i:=0 to 8 do with ListView1.Items.Add do begin s:='00'+inttostr(i+1); s:=copy(s,length(s)-1,2); Caption:=s; Subitems.Add('13800138000_'+s); Subitems.Add(FormatDateTime('yyyy-mm-dd hh:nn:ss',now)); end; end; procedure TForm1.Button1Click(Sender: TObject);//新增一行 var s:string; begin with ListView1.Items.Add do begin s:='00'+inttostr(ListView1.Items.Count); s:=copy(s,length(s)-1,2); Caption:=s; Subitems.Add('13800138000_'+s); Subitems.Add(FormatDateTime('yyyy-mm-dd hh:nn:ss',now)); end; end; procedure TForm1.Button2Click(Sender: TObject); var i:integer; s:string; begin for i:=ListView1.Items.Count-1 downto 0 do //删除奇数行 if i mod 2 = 0 then ListView1.Items.Item[i].Delete; for i:=0 to ListView1.Items.Count-1 do begin//重排序号 s:='00'+inttostr(i+1); s:=copy(s,length(s)-1,2); ListView1.Items.Item[i].Caption:=s; end; end;