Board index » delphi » Adding / deleting TListView columns at runtime

Adding / deleting TListView columns at runtime

        I have an application that needs to be able to add/delete columns of a
list view at run time. I can add the columns using something like:

procedure TForm1.Button1Click(Sender: TObject);
var
  lc: TListColumn;
  z: integer;
begin
  for z:= 0 to 4 do
    begin
      lc:= ListView1.Columns.Add;
      lc.Caption:= 'Column #' + IntToStr(ListView1.Columns.Count);
      lc.Width:= 75;
    end;
end;

I would like to remove all the columns with something like:

procedure TForm1.Button2Click(Sender: TObject);
var
  z: integer;
begin
  for z:= 0 to 4 do
    begin
      listView_DeleteColumn(ListView1.Handle, z);
    end;
end;

        This doesn't work. Not only does it not delete all of the columns, only
some of them, but the Column.Count property never gets updated. Which I
guess makes sense since this uses a message vs. Delphi collections. I need
to know how many columns are displayed so I can increase / decrease the
columns displayed at runtime. Anybody got any suggestions or pointers.

TIA!!

Sincerely,

Nathan Wilhelmi
nw60...@navix.net

 

Re:Adding / deleting TListView columns at runtime


        Seems that Columns.Clear does just what I'm looking for.  It's amazing
what writing your problem down does for your thought process:)

Nathan Wilhelmi

Re:Adding / deleting TListView columns at runtime


Quote
Nathan Wilhelmi wrote:
>         Seems that Columns.Clear does just what I'm looking for.  It's amazing
> what writing your problem down does for your thought process:)

> Nathan Wilhelmi

-- Actually there was a tech tip on this in the Delphi Developer Support section
of Borland's Web site also, which seemed to be exactly what you were describing.

-john

Re:Adding / deleting TListView columns at runtime


Quote
Nathan Wilhelmi wrote:

-- I was wondering, how many items do you have in your listView ??
I have about 700 and it seems to load Dog Slow.

Have you experienced any problems like this??

It seems that it's the control which is loading the items slowly.

thanks,
john

Quote
>         I have an application that needs to be able to add/delete columns of a
> list view at run time. I can add the columns using something like:

> procedure TForm1.Button1Click(Sender: TObject);
> var
>   lc: TListColumn;
>   z: integer;
> begin
>   for z:= 0 to 4 do
>     begin
>       lc:= ListView1.Columns.Add;
>       lc.Caption:= 'Column #' + IntToStr(ListView1.Columns.Count);
>       lc.Width:= 75;
>     end;
> end;

> I would like to remove all the columns with something like:

> procedure TForm1.Button2Click(Sender: TObject);
> var
>   z: integer;
> begin
>   for z:= 0 to 4 do
>     begin
>       listView_DeleteColumn(ListView1.Handle, z);
>     end;
> end;

>         This doesn't work. Not only does it not delete all of the columns, only
> some of them, but the Column.Count property never gets updated. Which I
> guess makes sense since this uses a message vs. Delphi collections. I need
> to know how many columns are displayed so I can increase / decrease the
> columns displayed at runtime. Anybody got any suggestions or pointers.

> TIA!!

> Sincerely,

> Nathan Wilhelmi
> nw60...@navix.net

Other Threads