Solved

How to edit the subitems of a list view

Posted on 2004-10-08
15
345 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

24 Experts available now in Live!

Get 1:1 Help Now