Solved

TListView

Posted on 2001-06-20
6
476 Views
Last Modified: 2010-04-06
How do I add items (text) in a Tlistview object?
sample code please!
thanx
0
Comment
Question by:gikam
6 Comments
 
LVL 5

Accepted Solution

by:
TheNeil earned 30 total points
ID: 6210145
Like this:

procedure TfrmMissionMain.Button1Click(Sender: TObject);
VAR
  NewItem : TListItem;
begin
  NewItem := ListView1.Items.Add;
  NewItem.Caption := 'Some text';
end;

The Neil =:)
0
 
LVL 2

Author Comment

by:gikam
ID: 6210180
how do I select the column where the item will be added?
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6210220

If you are using the listview in report mode then the Caption property of a TListItem corresponds to the first column in the listview. To add text to other columns you need to add strings to the subitems property which is of type TStrings. eg :

VAR
 NewItem : TListItem;
begin
 NewItem := ListView1.Items.Add;
 NewItem.Caption := 'Some text'; // this is the first column

 NewItem.SubItems.Add('Text 2'); // this is the second column

 NewItem.SubItems.Add('Text 3'); // this is the second column

  // and so on...

end;

regards

Jo
0
 
LVL 1

Expert Comment

by:alx512
ID: 6255346
procedure TfrmMissionMain.Button1Click(Sender: TObject);
VAR
 NewItem : TListItem;
begin
 NewItem := ListView1.Items.Add;
 NewItem.Caption := 'Some text';

 ListView1.Selected := NewItem;
 ListView1.Focused  := NewItem;
end;
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8685004
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept TheNeil's comment as answer

I would have recommended a split, but the points are not high enough to warrant that, and TheNeil answered the original question first.

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question