Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

D4: TListView does not resize columns

1 view
Skip to first unread message

Frank Heyne

unread,
Jul 4, 2000, 3:00:00 AM7/4/00
to
Hello,

I tried to make it simplest, so you can cut and paste the code to see my
problem - when resizing the width of a column, the ListView is not
repainted and looks quite ugly. The problem seems to occur only when
OwnerDraw = true!
I hope someone has an idea how I can get this to work as expected?
Thank you in advance for your time!

===============
// File LV.pas
unit LV_Unit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;

type
TForm1 = class(TForm)
ListView1: TListView;
procedure ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw:
Boolean);
private
public
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
b: integer;
rs: TSize;
r, myrect: TRect;
begin
r := Item.DisplayRect(drBounds);
with Sender.Canvas do
begin
b := ListView1.columns[0].width;
rs := TextExtent(item.caption);
TextRect(r, b-3-rs.cx, r.top+1, item.caption);
myRect := r;
inc(myrect.left, b);
myRect.Right := myrect.left + ListView1.columns[1].width;
TextRect(myRect, myRect.left+2, MyRect.top+1, item.subitems[0]);
end;
DefaultDraw := false;
end;

end.

===============
// File LV.dfm
object Form1: TForm1
Left = 188
Top = 107
Width = 377
Height = 276
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ListView1: TListView
Left = 10
Top = 6
Width = 347
Height = 237
Columns = <
item
Caption = 'Column 1'
end
item
Caption = 'Column 2'
end>
HotTrackStyles = []
Items.Data = {
B10000000200000000000000FFFFFFFFFFFFFFFF01000000000000001A414141
4141414141414141414141414141414141414141414141185757575757575757
5757575757575757575757575757575700000000FFFFFFFFFFFFFFFF01000000
0000000025424242424242424242424242424242424242424242424242424242
42424242424242424242265A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A
5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A}
OwnerDraw = True
TabOrder = 0
ViewStyle = vsReport
OnCustomDrawItem = ListView1CustomDrawItem
end
end
==============

--
Greetings
Frank Heyne

To reply to me personally, remove the x from the email address!

0 new messages