Solved

How to edit the subitems of a list view

Posted on 2004-10-08
15
346 Views
Last Modified: 2012-05-05
... in report style.
0
Comment
Question by:__alex
  • 8
  • 3
  • 3
  • +1
15 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12258036
procedure TForm1.FormCreate(Sender: TObject);
var
  item    : TListItem;
begin
  // add one item
  item := TListItem.Create(ListView1.Items);
  item := ListView1.Items.Add;
  item.Caption := 'Column 1';
  item.SubItems.Add('Column 2');
  item.SubItems.Add('Column 3');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  lc_item    : TListItem;
begin
  // modify it
  lc_item := ListView1.Items[0];
  lc_item.SubItems[0] := 'Change second column';
end;
0
 
LVL 2

Accepted Solution

by:
gary_williams earned 250 total points
ID: 12258039
By "edit" do you mean "modify programmatically" or "allow the user to modify via typing into a cell"?

If the former case, simply get a pointer to the TListItem you want to change (either ListView.Selected or ListView.Items[RowNumber]), then add, insert, delete, or modify an element in its TStrings property named "SubItems".

The latter case is not possible with TListView.  You might consider using a TStringGrid instead.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12258234
procedure TFormMain.Button1Click(Sender: TObject);
begin
  ListView1.Items[1].SubItems[0] := 'Kylie Minogue';
end;
0
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.

 
LVL 12

Expert Comment

by:esoftbg
ID: 12258242
The above change the first Subitem of the second Item
0
 
LVL 2

Author Comment

by:__alex
ID: 12258322
> By "edit" do you mean "modify programmatically" or "allow the user to modify via typing into a cell"?
Mea culpa! I meant the counterpart to TListItem.EditCaption (= typing into cell).
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12258546
Why don't use a StringGrid ?
0
 
LVL 2

Author Comment

by:__alex
ID: 12258898
Well, I'll head for the string grid thingy, thanks!
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12260305
> "How to edit the subitems of a list view"
Just a little note:   If the question was
   "How to edit the subitems of a list view AT DESIGN TIME"  it wold be more clear

thanks ....
0
 
LVL 2

Expert Comment

by:gary_williams
ID: 12261506
But he's not talking about design time.  He's talking about at runtime.  (notice the TListItem.EditCaption comment four comments up from this one.)
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12266443
I so sorry again, but at runtime works only for Items:
  ListView1.Items[1].EditCaption;
but not for subitems:
  ListView1.Items[1].SubItems[0].EditCaption;  // so EditCaption method is not for subitems
May be I am wrong, if so excuse me, but the question is: "How to edit the subitems of a list view", "... in report style."

0
 
LVL 2

Expert Comment

by:gary_williams
ID: 12267434
Yes, you are correct.  Were you implying that I was implying that EditCaption worked for SubItems?  I only mentioned the EditCaption comment above as evidence that the person posing the question was interested in a run-time solution, not a design-time solution.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12268361
O.k. who asks the question desides which comment is useful ....
0
 
LVL 2

Author Comment

by:__alex
ID: 12274426
How I like flame wars...

I never talked about design time.
gary_williams told me:
  - that it's not possible to edit the subitems of a listview via GUI
  - to use a TStringGrid instead
Even though my question was not very accurate he gave me the neccessary hints.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12274485
 __alex,
Excuse me, if it seems like a > flame wars...,
but I am not resent or disappointed,
I just specify:
> O.k. who asks the question desides which comment is useful ....
It is your right to grade the comment you like !
I don't conest anything !
:-))
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12274490
>I don't conest anything !
I don't contest anything !

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now