为了加快显示速度,我是用virtual listview方法加载数据 OwnerDraw是为了显示彩色数据。代码:procedure TForm1.ListView1DrawItem(Sender: TCustomListView; Item: TListItem; Rect: TRect; State: TOwnerDrawState); var bkcolor,ftcolor:TColor; i,j:Integer; x,w:integer; Arect:TRect; begin if odSelected in state then begin bkcolor:=$00C56549; ftcolor:=clWhite; end else begin ftcolor:=clBlack; if Item.Index mod 2 = 0 then bkcolor:=$FFFFF0 else bkcolor := clWhite; if Item.SubItems[0]= '目录' then bkcolor:=$00F2FAFD; end; with TListView(Sender) do begin Canvas.Brush.Color:=bkColor; Canvas.Font.Color:=ftcolor; Canvas.FillRect(Rect); //Canvas.TextOut(Rect.left+6,Rect.Top-1,Item.caption); x:=6; w:=Columns[0].Width; Arect.Top:=Rect.Top ; Arect.Left:= x; Arect.Right:=x+w; Arect.Bottom:=Arect.Top+13; Canvas.TextRect(ARect,x+6,Rect.Top -1,Item.Caption); x := 0; for i:= 0 to Item.SubItems.Count -1 do begin //Canvas.TextOut(x,Rect.Top -1, Item.SubItems[i]); x:= x + Columns[i].Width ; w:=Columns[i+1].Width; Arect.Top:=Rect.Top ; Arect.Left:= x; Arect.Right:=x+w; Arect.Bottom:=Arect.Top+13; //13--Item 的高度 if i < Item.SubItems.Count -1 then Canvas.TextRect(ARect,x+6,Rect.Top -1,Item.SubItems[i]) else Canvas.TextRect(ARect,x+Columns[i+1].Width-Canvas.TextWidth(Item.SubItems[i])-6,Rect.Top -1,Item.SubItems[i]); end; end; 恩德;
OwnerDraw是为了显示彩色数据。代码:procedure TForm1.ListView1DrawItem(Sender: TCustomListView;
Item: TListItem; Rect: TRect; State: TOwnerDrawState);
var
bkcolor,ftcolor:TColor;
i,j:Integer;
x,w:integer;
Arect:TRect;
begin if odSelected in state then
begin
bkcolor:=$00C56549;
ftcolor:=clWhite;
end
else begin
ftcolor:=clBlack;
if Item.Index mod 2 = 0 then
bkcolor:=$FFFFF0
else
bkcolor := clWhite;
if Item.SubItems[0]= '目录' then
bkcolor:=$00F2FAFD;
end; with TListView(Sender) do
begin
Canvas.Brush.Color:=bkColor;
Canvas.Font.Color:=ftcolor;
Canvas.FillRect(Rect); //Canvas.TextOut(Rect.left+6,Rect.Top-1,Item.caption);
x:=6;
w:=Columns[0].Width;
Arect.Top:=Rect.Top ;
Arect.Left:= x;
Arect.Right:=x+w;
Arect.Bottom:=Arect.Top+13;
Canvas.TextRect(ARect,x+6,Rect.Top -1,Item.Caption); x := 0;
for i:= 0 to Item.SubItems.Count -1 do
begin
//Canvas.TextOut(x,Rect.Top -1, Item.SubItems[i]);
x:= x + Columns[i].Width ;
w:=Columns[i+1].Width;
Arect.Top:=Rect.Top ;
Arect.Left:= x;
Arect.Right:=x+w;
Arect.Bottom:=Arect.Top+13; //13--Item 的高度
if i < Item.SubItems.Count -1 then Canvas.TextRect(ARect,x+6,Rect.Top -1,Item.SubItems[i])
else Canvas.TextRect(ARect,x+Columns[i+1].Width-Canvas.TextWidth(Item.SubItems[i])-6,Rect.Top -1,Item.SubItems[i]);
end;
end;
恩德;