I have a TListView
linked in LiveBindings with a TFDMemTable
. I load data in the FDMemTable using LoadFromFile
(I have for example 20 record).
When I delete a record from the FDMemTable, the RecordCount
is decreased but the TListView
is not refreshed, it continue to display the 20 records loaded on the LoadFormFile
.
If, with the FDMemTable: I .SaveToFile
, .Close
, and reload with .LoadFromFile
, the TListView
now display the change.
This is the same behavior if I use the CachedUpdate
of FDMemTable or not.
I've tried to call TFDMemTable.Refresh
and TListView.Repaint
without succes.
Is it possible to call the TListView
to refresh his "linked" set of data ?
When I delete a record in the FDMemTable, why no visible refresh occur on the TListView
?
EDIT: I must add a thing, the record is deleted programmatically.
The desired functionality is to delete sone unwanted record in the FDMemTable
and display the remaining record to the user with the TListView
.
In LiveBindings Designer, by linking the Synch
of the ListView
to the *
of the FDMemTable
, the ListView
now display the resulting record.
Also in my last algorithm, because I use .BeginBatch / .EndBatch
(that disable data-aware refreshing), while processing data for removing unwanted record I've to disable the LiveBinding link temporarily (cause I use different sorting index whitin the processing of the data): LinkListControlToField1.Active := false;
and "re-link" it after processing: LinkListControlToField1.Active := true;
The livebindings isn't consistently bi-directional here. The ListView livebindings was designed to work from the UI to the dataset direction, but only mostly.
If you enable CanSwipeDelete
, you can expect that to work, if you know how.
In my case, on Android, I found myself writing code to ensure that the listview kept sync with the dataset, even though there is livebindings active. In my case is a TClientDataset named CDSAnimals, with a unique key value of TagID. I hope this helps.
procedure TfrmLiveMain.ListView1DeletingItem(Sender: TObject; AIndex: Integer;
var ACanDelete: Boolean);
var
LI: TListViewItem;
LIO: TListItemText;
begin
// check that the livebindings is doing it's job, if not
// do it myself
ACanDelete := False;
LI := ListView1.Items[AIndex];
LIO := LI.Objects.FindObjectT<TListItemText>('Text1');
FTagID := LIO.Text;
if ClientModule2.CDSAnimals.FieldByName('TagID').AsString <> FTagID then
ClientModule2.CDSAnimals.Locate('TagID', FTagID, []);
if ClientModule2.CDSAnimals.FieldByName('TagID').AsString = FTagID then
begin
ACanDelete := True; // causes the listview item to be deleted without
// affecting the corresponding dataset record
end;
end;
procedure TfrmLiveMain.ListView1DeleteItem(Sender: TObject; AIndex: Integer);
begin
// this is called with the wrong index!
if ClientModule2.CDSAnimals.Locate('TagID', FTagID, []) then
if ClientModule2.CDSAnimals.FieldByName('TagID').AsString = FTagID then
begin
// now delete the corresponding record too
ClientModule2.CDSAnimals.Delete; // and it works!
end;
end;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.