[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Add, Change and Deleting Itemns or Columns on TListView

Posted on 2006-07-15
11
Medium Priority
?
1,950 Views
Last Modified: 2011-10-03
How Can I do this command's on TListView

This is how I insert a Item:

     ListView1.Items.Insert(conaux.ThreadID).Caption := ConAux.IP;


How can I do the rest:

delete or change item;
Insert, delete or change column;
Insert, delete or change subitems;


0
Comment
Question by:rafaelrgl
  • 9
  • 2
11 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 17116535
var itm:TListItem;

to add items:


itm:=ListView1.Items.Add;
itm.Caption:=ConAux.IP

to add subitems:

itm.SubItems.Add('SubItem1');
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 17116550
To delete a item:

ListView.Items.Item[0].Delete;

Where 0 is your wished item index.

You can't delete the subitem but can set to '' the Caption. When delete the item the subitems gone too :)

To cange an item:

ListView1.Items.Item[0].Caption := 'Item2';

or a subitem:

ListView1.Items.Item[0].SubItems[0]:='';
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 17116556
Add column:

ListView1.Columns.Add;
ListView1.Column[ListView1.Columns.Count-1].Caption:='Test';

Change column:

ListView1.Column[MyColumnIndex].Caption:='Test 2';

Delete a column:

ListView1.Column[MyColumnIndex].Destroy;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:ginsonic
ID: 17116558
Sorry, I write that subitems can't be deleted. Not true, you can do :

ListView1.Items.Item[0].SubItems.Delete(0);

Change 0 with your indexes.
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17117351
insert   item        :        ListView1.Items.Insert(conaux.ThreadID).Caption := ConAux.IP;
delete  item        :        ListView.Items.Item[0].Delete;
change item        :       ListView1.Items.Item[0].Caption := 'Item2';
insert   subitem   :       ListView1. ?????????????????????????????????????
delete  subitem    :       ListView1.Items.Item[0].SubItems.Delete(0);
change subitem   :        ListView1.Items.Item[0].SubItems[0]:='';

insert   column    :       ListView1.Columns.Add;
                                  ListView1.Column[ListView1.Columns.Count-1].Caption:='Test';

delete   column    :       ListView1.Column[MyColumnIndex].Destroy;
change column    :       ListView1.Column[MyColumnIndex].Caption:='Test 2';

question:

how can i change the index 0 to a function that find the index using the caption
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 17122549
Not my code. Found sometime ago on net:

function FindListviewItem( lv: TListview; const S: String; Column: Integer ): TListItem;
var
  i: Integer;
  found: Boolean;
begin
  Assert( Assigned( lv ));
  Assert( (lv.viewstyle = vsReport) or (column = 0) );
  Assert( S <> '' );
  for i := 0 To lv.items.count - 1 do
  begin
    result := lv.Items[i];
    if column = 0 then
      found := AnsiCompareText( result.caption, S ) = 0
    else
      if column <= result.subitems.count then
        found := AnsiCompareText( result.subitems[column - 1], S ) = 0
      else
        found := false;
    if found Then
      Exit;
  end;

  Result := nil;
end;


procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
  i:=ListView1.Items.IndexOf(FindListviewItem( ListView1, 'Item2', 0 ));
  ShowMessage(IntToStr(i));
end;
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 2000 total points
ID: 17122603
For subitems adding can use:

ListView1.Items.Item[0].SubItems.Add('SubItem1');

But I preffer next way ( the new item is added at the end of items list and not inserted somewhere inside the list ):

procedure TForm1.Button1Click(Sender: TObject);
var itm:TListItem;
begin
  itm:=ListView1.Items.Add;
  itm.Caption:='Item1';
  itm.SubItems.Add('SubItem1');
end;
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 17131396
any comment
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 17138542
Have my comments solve your problems?
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 17140617
yes, thank you so much.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 17143675
My pleasure!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

872 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