Entwickler-Ecke

Datenbanken - devexpress quantumgrid master-detail


Josef-B - Do 31.03.11 08:06
Titel: devexpress quantumgrid master-detail
Ich verzweifle mal wieder am Quantumgrid ;-)

Ich möchte zwei Firebird-Tabellen darstellen als Master-Detail mit zwei Views
im Grid.

Der Grid-Mode ist false

Ich krieg die Verknüpfung nicht hin.

Es gibt zwei Datasets

DSMaster und DSDetail
Die beiden sind so verknüpft:


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
DSMaster.selectsql.text := 'Select * from Inventur';
DSDetail.selectsql.Text := 'Select * from Inventur_pos where pos_id = :ID order by pos_id';

DSDetail.datasource := DatasourceMaster;

ViewMaster.keyfieldnames := 'ID';
ViewDetail.keyfieldnames := 'ID';
ViewDetail.Masterkeyfieldnames := 'ID';
ViewDetail.Detailkeyfieldnames := 'POS_ID';


Mein Problem ist, die Details werden nicht richtig angezeigt, mal werden alle Details der gesamten
Tabelle bei allen Mastersätzen angezeigt, mal irgendwas, kann ich keine Regel beschreiben

Ich hab mir die Hilfe angesehen, danach brauchte man wohl die Verknüpfung der Datasets gar nicht,
würde bei gridmode = false der Datacontroller des Views machen, oder?

Irgendwie müsste man glaub ich noch die Daten sortieren?

das hier verstehe ich nicht ganz aus der Devexpress-Hilfe

Sorting the detail dataset

The last step of setting up a master-detail relationship is to sort the detail dataset (for parameterized queries this is not necessary). Providing that the detail dataset is sorted, the data controller will correctly retrieve all the necessary records from it. The detail dataset must be sorted against the fields specified by the DetailKeyFieldNames property.

To enable sorting for query datasets, you should use the "ORDER BY" SQL command. For TTable and TCustomADODataSet components, the sorting of dataset records is implemented via the IndexFieldNames property. In this example, we need to set the IndexFieldNames property of the dsFilmsPersonsStaff dataset to FILMID (the same value as for the tvFilmsPersonsStaff.DataController.DetailKeyFieldNames property).


Josef-B - Mo 11.04.11 08:26

Falls es jemand mal irgendwann liest, möchte ich es nach intentivem Studium der
Devexpress Hilfe und diverser support-seiten selbst beantworten, was ich bisher
dazu rausgefunden habe:

Im Gridmode = true funktioniert die Verknüpfung über die Datasets und Datasources.

Im Gridmode = false werden die Tabellen über die Views verknüpft.

Das DetailView muss dabei auf alle Detail-Sätze Zugriff haben, nicht nur auf die
DetailSätze des Master-Datensatzes.

also zb: 'Select * from Detail-Tabelle order by key' nicht
'Select * from Detail-Tabelle where Key_id = :Master_ID'

Und die Detail-Sätze müssen nach dem Schlüssel sortiert sein.