• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Help needed with code (ListView)

Hi experts,

I need some help with code.

I am using the following:

var i: integer;
begin
     ListView1.Columns.Add;
  for i := 0 to listView1.Items.Count-1 do
    listView1.Items[i].Caption :=('hello');
end;

Right now this code add "hello" to every field on cloumn 0

I need to create a new header name instead and then add "hello" to each field in the new column.

Hope you can help

Thanks

ST3VO


0
ST3VO
Asked:
ST3VO
  • 3
  • 2
1 Solution
 
MerijnBSr. Software EngineerCommented:
does this column have to be the first one?
0
 
ST3VOAuthor Commented:
No...I actually would prefare it to be the after the last column!

0
 
MerijnBSr. Software EngineerCommented:
pfew, that saves a lot of work:

procedure TForm1.Button1Click(Sender: TObject);
var NewColumn: TListColumn;
    i: integer;
begin
 NewColumn := ListView1.Columns.Add();
 NewColumn.Caption := 'new column';
 NewColumn.Width := 100;
 // set more properties for the column if you want

 for i := 0 to ListView1.Items.Count - 1 do
  ListView1.Items[i].SubItems.Add('hello');
end;
0
 
MerijnBSr. Software EngineerCommented:
be aware though, if you want to shuffle around with columns TListView is not a very good component to use!
0
 
ST3VOAuthor Commented:
Perfect as usual! Thanks!!! :o)

Ref: TListView and Columns I am actually using TAdvListView (TMS) I just thought I'd post as TListView as the code is compatible on AdvListView too and I would get faster response posting the question as TListView than TAdvListView.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now