2.如下图:ListView左滑删除的功能到底应该调用什么事件呢,我现在写得代码如下:会报错,错误信息:At begining of Table
procedure TFrmMain.ListView1DeleteItem(Sender: TObject; AIndex: Integer); begin CDS1.RecNo:=ListView1.ItemIndex+1; UID:=CDS1.FieldByName('UID').AsString; if CDS1.FieldByName('Deployer').AsString = FrmMain.Label1.Text then begin cds1.Close; CDS1.CommandText:='delete from WorkTask where UID = '''+UID+''' '; CDS1.Execute; CDS1.ApplyUpdates(0); end else begin ShowMessage('你不是创建人,不能删除此项目'); Exit; end; end;
procedure TForm1.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem); begin MyItemClicked := AItem; // the current item... end;
procedure TForm1.ListView1DeletingItem(Sender: TObject; AIndex: Integer; var ACanDelete: Boolean); begin // before delete item ... Delete or not? end;
procedure TForm1.ListView1DeleteItem(Sender: TObject; AIndex: Integer); begin Memo1.Lines.Add('Occurs when a user requests the deletion of a list view item, after this deletion takes place.: ' + AIndex.ToString); end;
procedure TForm1.ListView1ButtonClick(const Sender: TObject; const AItem: TListItem; const AObject: TListItemSimpleControl); var MyNextItemIndex :integer; begin if (MyItemClicked = nil) then exit; // // if ((MyItemClicked.Index + 1)<= (ListView1.Items.Count - 1)) then ListView1.ItemIndex := MyItemClicked.Index + 1; // //ListView1.EditMode := false; // MyItemClicked := nil; // ShowMessage('this item was deleted...'); end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
var LVI: TListViewItem; begin EmployeeTable.Open; // while not EmployeeTable.Eof do begin LVI := ListView1.Items.Add; LVI.Text := EmployeeTable.Fields[1].AsString; LVI.Tag := EmployeeTable.RecNo; // store the real recno value in "Tag" or any other property "integer" EmployeeTable.Next; end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
ListView is not "aware-data", then, you needs use some way to store the values... for example, using "TAG/TAGString" properties!!!
ListView1.ItemIndex = "n" item in a total of items on ListView (Count)!!! Recno = current record on the table!!!
you see? this values is "distinct" each other!!
for example: ---------- using "TAG" property in listview items, you can store the "RECNO" value, then, you use it like a "bookmark" (fake). ... // all ListView "Items" have: ... ListView1.ItemXXX.Tag := ID value in table -- as above showed
if DataSetXXXX.Locate('ID', ListViewItemXXXX.Tag, []) then // what to do? ;
---------- LiveBinding use: it's more easy!
if you are using "LiveBinding" you can use: just this line!!!
procedure TForm1.ListView1ItemClick(const Sender: TObject; const AItem: TListViewItem); begin ShowMessage(BindSourceDB1.DataSet.FieldByName('FIRST_NAME').AsString); end;
此帖子包含附件: 大小:22.4K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
"BindSourceDB" works like a "DataSource" in common datasets!!!
if ListView go to another "item", then, using LiveBinding, BindSourceDB you go to another record ... relationship: 1 to 1 ----------
Using ListView in DinamicAppearance, you can get the data from Items that way:
if (ListView1.ItemIndex > -1) then ShowMessage(ListView1.Items[ListView1.ItemIndex].Data['Text2'].AsString);
"Text2" is the name from item on DinamicAppearance style.
NOTE: "Text" does not works in DynamicAppearance, because it is used for another style, like "ListItem", for example.
My tip: --- Change your Dataset to FireDAC (FDQuery "for database" or FDMemTable "for memory usage") is better and works with all data sources, like: Databases, ODBC, XML, JSON, include text files!!! --- using new technologies like FireDAC your app have a long-life
此帖子包含附件: 大小:53.8K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
Memo1.Lines.Clear; // for var MyItem in ListView1.ItemAppearanceObjects.ItemObjects.Objects do Memo1.Lines.Add( ListView1.Items[ListView1.ItemIndex].Data[ MyItem.Name ].AsString );
NOTE: if "MyItem.Name = ''", dont worry!!! None error, just "empty" value will be showed.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3