Solved

TListView

Posted on 2001-06-20
6
474 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

831 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