Domanda

I have a form with 2 grids showing records selected using master-detail option on Devart UniQuery. This working very nice showing the wanted records in detail that relates to master. I have the option to select records (companies) using a filter. This is done by 30 buttons with a letter on each and then when pressing one I set the filter with this code

procedure TfrmJsCompanies.ButtonClick(Sender: TObject);
var
  ButtonValue: char;
  FilterString: string;
begin
  ButtonValue := (Sender as TcxButton).Caption[1];
  FilterString := ButtonValue + '%';
  with grdCompaniesView1.DataController.Filter.Root do
    begin
      Clear;
      BoolOperatorKind := fboOr;
      AddItem(colCompany_Name, foLike, FilterString, FilterString);
    end;
  grdCompaniesView1.DataController.Filter.Active := True;
  grdCompaniesView1.FilterRow.Visible := False;
  ActiveControl := grdCompanies;
end;

If I do this i get the result I expect unless I first press a button that gives me master records that has detail records and there after press a button that gives me no master records - in this case the detail records from the previous selection are still shown in my detail grid

What can I do to get rid of this?

È stato utile?

Soluzione

This behavior is caused by the fact that filtering is executed on the cxGrid level, but not on the DataSet level and, as a result, the DataSet is not filtered.
One way to deal with that could be:

procedure TForm1.DetailViewFilterRecord(ADataController: TcxCustomDataController; ARecordIndex: Integer;
  var Accept: Boolean);
begin
  Accept := MasterView.DataController.FilteredRecordCount >0;
end;

procedure TForm1.MasterViewDataControllerFilterChanged(Sender: TObject);
begin
   DetailView.DataController.Refresh
end;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top