Delphi 11 ListView实现删除一行
作者:互联网
实现下图的界面,用ListView显示一个数据集的内容:
点Delete删除所在行,下面是实现的代码:
procedure TForm3.FormCreate(Sender: TObject); var I: Integer; begin //prepare dataset for I := 1 to 10 do begin clientdataset1.Append; clientdataset1.Fields[0].Value:=i; clientdataset1.Post; end; LinkFillControlToField1.Active:=False; LinkFillControlToField1.Active:=True; end; procedure TForm3.ListView1ItemClickEx(const Sender: TObject; ItemIndex: Integer; const LocalClickPos: TPointF; const ItemObject: TListItemDrawable); begin if (ListView1.Selected<>nil) and //用户选择了一行 (ItemObject is TListItemTextButton) and (SameText(TListItemTextButton(ItemObject).Text,'delete')) then //点击delete按钮 Listview1.Items.Delete(ListView1.Selected.Index); //删除选择行 end;
注意:在ListView1ItemClickEx事件中,不要使用ItemIndex,这个值不准!
标签:11,ListView1,clientdataset1,end,Delphi,begin,ItemObject,const,ListView 来源: https://www.cnblogs.com/kinglandsoft/p/16033569.html