Home > database >  Listbox does not show the changes made to the Dataset
Listbox does not show the changes made to the Dataset

Time:11-17

I have a FMX ComboBox connected through LiveBindings to a ClientDataset. Everything works fine, until I needed to filter the data from the ClientDataset. After applying the filter, ComboBox.Items and ComboBox.ListItems are ok, i.e., it is the data contained in the filtered ClientDataset. But the data that the ComboBox listbox shows is always the same: the data that the ClientDataset contained the first time the listbox was displayed.

procedure TForm14.Button1Click(Sender: TObject);
begin
  LinkFillControlToField1.Active := False;
  ClientDataset1.Filter := 'TYPE = ''N''';
  Clientdataset1.Filtered := not ClientDataset1.Filtered;
  // Deactivate and Reactivate the link is necessary to refresh the data
  LinkFillControlToField1.Active := True;
end;

In that code I change the filter to the ClientDataset and I deactivate the LinkFillControlToField and after applying the filter I activate it again to refresh the data. It works without problems with TListBox and other controls, but not with a TComboBox, although ComboBox.Items and ComboBox.ListItems do contain the correct data, but it is not the one shown in the combobox listbox.

Is there a way to solve this, using LiveBindings ? I have looked for properties and methods of the ComboBox (Repaint for example), the LinkFillControlToField and the BindSourceDB, but nothing has worked for me.

I use Delphi 10.4 Update 2, Firemonkey Windows application (32 or 64) running on Windows 10.

TIA.,

Ricardo

CodePudding user response:

I had the same problem. My data source was TFireDAC TQuery. I submitted a change to a parma contained in the query. My solution to my problem was to insert the line to explicitly clear the list of items.

if (SCM != NULL && SCM->qrySession->Active) {
    SCM->qrySession->DisableControls();
    // remove all the strings held in the combobox
    // note cmbSessionList->Clear() doesn't work here.
    cmbSessionList->Items->Clear();
    SCM->qrySession->Close();
    // ASSIGN PARAM to display or hide CLOSED sessions
    SCM->qrySession->ParamByName("HIDECLOSED")->AsBoolean = fHideClosedSessions;
    SCM->qrySession->Prepare();
    SCM->qrySession->Open();
    SCM->qrySession->EnableControls();
}
  • Related