Board index » delphi » TListView / vsList problem

TListView / vsList problem

I am having some difficulty in sizing the 'column' width in a TListView
with style as vsList.

The ListView_SetColumnWidth macro seems to have no effect on the width, and
much of the data in the List is unviewable.

I tried changing to vsReport, but get access violations when run. (would
prefer to use vsList anyway)

Using Delphi 5 / WinXP

Any help would reduce hair loss and therefore be greatly appreciated!

Regards,

Brett

--
------------------------
Of all the things I've lost, I miss my mind the most..

 

Re:TListView / vsList problem


I think you cannot change it!

I have had the same nightmare.

It is designed to customise it's own width. I think the width is determined
from the text that needs to be displayed. And it also means that you have to
use the default drawing. There's no way around that with TListview.

In vsReport, you can change the width through the Columns objects
(Columns.Width). This only works for OwnerData = True if I'm correct, but
that's advisable anyway if you want many elements in your listview.

Have a look at ABC-View Manager, it also uses a TListview.

Nils
www.abc-view.com

Quote
Brett Northcott <bre...@bigpond.net.au> wrote in message

news:3c713fbf$1_1@dnews...
Quote
> I am having some difficulty in sizing the 'column' width in a TListView
> with style as vsList.

> The ListView_SetColumnWidth macro seems to have no effect on the width,
and
> much of the data in the List is unviewable.

> I tried changing to vsReport, but get access violations when run. (would
> prefer to use vsList anyway)

> Using Delphi 5 / WinXP

> Any help would reduce hair loss and therefore be greatly appreciated!

> Regards,

> Brett

> --
> ------------------------
> Of all the things I've lost, I miss my mind the most..

Re:TListView / vsList problem


Am I missing something ? It works for me. Delphi 4.0 / WinXP. Here is the
code, good luck:

{-----------}

unit Unit1;

interface

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

const
  PREDEFINED_WIDTH = 25;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  CurrentWidth: Integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
     if CurrentWidth > PREDEFINED_WIDTH then begin
        Dec(CurrentWidth);
        ListView_SetColumnWidth(ListView1.Handle, 0, CurrentWidth);
     end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
   li: TListItem;
   lc: TListColumn;
   i: Integer;
begin
    CurrentWidth := 100;
    lc := ListView1.Columns.Add;
    lc.Width := CurrentWidth;
    for i:=1 to 50 do begin
        li := ListView1.Items.Add;
        li.Caption := IntToStr(i);
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     if ListView1.ViewStyle = vsReport then
        ListView1.ViewStyle := vsList
     else
        ListView1.ViewStyle := vsReport;
end;

end.

{----------}

Quote
"Brett Northcott" <bre...@bigpond.net.au> wrote in message

news:3c713fbf$1_1@dnews...
Quote
> I am having some difficulty in sizing the 'column' width in a TListView
> with style as vsList.

> The ListView_SetColumnWidth macro seems to have no effect on the width,
and
> much of the data in the List is unviewable.

> I tried changing to vsReport, but get access violations when run. (would
> prefer to use vsList anyway)

> Using Delphi 5 / WinXP

> Any help would reduce hair loss and therefore be greatly appreciated!

> Regards,

> Brett

> --
> ------------------------
> Of all the things I've lost, I miss my mind the most..

Other Threads