Solved

How to edit the subitems of a list view

Posted on 2004-10-08
15
344 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

11 Experts available now in Live!

Get 1:1 Help Now