rafaelrgl
asked on
Add, Change and Deleting Itemns or Columns on TListView
How Can I do this command's on TListView
This is how I insert a Item:
ListView1.Items.Insert(con aux.Thread ID).Captio n := ConAux.IP;
How can I do the rest:
delete or change item;
Insert, delete or change column;
Insert, delete or change subitems;
This is how I insert a Item:
ListView1.Items.Insert(con
How can I do the rest:
delete or change item;
Insert, delete or change column;
Insert, delete or change subitems;
To delete a item:
ListView.Items.Item[0].Del ete;
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].Ca ption := 'Item2';
or a subitem:
ListView1.Items.Item[0].Su bItems[0]: ='';
ListView.Items.Item[0].Del
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].Ca
or a subitem:
ListView1.Items.Item[0].Su
Add column:
ListView1.Columns.Add;
ListView1.Column[ListView1 .Columns.C ount-1].Ca ption:='Te st';
Change column:
ListView1.Column[MyColumnI ndex].Capt ion:='Test 2';
Delete a column:
ListView1.Column[MyColumnI ndex].Dest roy;
ListView1.Columns.Add;
ListView1.Column[ListView1
Change column:
ListView1.Column[MyColumnI
Delete a column:
ListView1.Column[MyColumnI
Sorry, I write that subitems can't be deleted. Not true, you can do :
ListView1.Items.Item[0].Su bItems.Del ete(0);
Change 0 with your indexes.
ListView1.Items.Item[0].Su
Change 0 with your indexes.
ASKER
insert item : ListView1.Items.Insert(con aux.Thread ID).Captio n := ConAux.IP;
delete item : ListView.Items.Item[0].Del ete;
change item : ListView1.Items.Item[0].Ca ption := 'Item2';
insert subitem : ListView1. ?????????????????????????? ?????????? ?
delete subitem : ListView1.Items.Item[0].Su bItems.Del ete(0);
change subitem : ListView1.Items.Item[0].Su bItems[0]: ='';
insert column : ListView1.Columns.Add;
ListView1.Column[ListView1 .Columns.C ount-1].Ca ption:='Te st';
delete column : ListView1.Column[MyColumnI ndex].Dest roy;
change column : ListView1.Column[MyColumnI ndex].Capt ion:='Test 2';
question:
how can i change the index 0 to a function that find the index using the caption
delete item : ListView.Items.Item[0].Del
change item : ListView1.Items.Item[0].Ca
insert subitem : ListView1. ??????????????????????????
delete subitem : ListView1.Items.Item[0].Su
change subitem : ListView1.Items.Item[0].Su
insert column : ListView1.Columns.Add;
ListView1.Column[ListView1
delete column : ListView1.Column[MyColumnI
change column : ListView1.Column[MyColumnI
question:
how can i change the index 0 to a function that find the index using the caption
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 (FindListv iewItem( ListView1, 'Item2', 0 ));
ShowMessage(IntToStr(i));
end;
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
var i:integer;
begin
i:=ListView1.Items.IndexOf
ShowMessage(IntToStr(i));
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
any comment
Have my comments solve your problems?
ASKER
yes, thank you so much.
My pleasure!
to add items:
itm:=ListView1.Items.Add;
itm.Caption:=ConAux.IP
to add subitems:
itm.SubItems.Add('SubItem1