Blog

All Blog Posts  |  Next Post  |  Previous Post

Next Generation Data Grid for Delphi: Master-Detail

Tuesday, October 29, 2024

TMS Software Delphi  Components

Intro

If you’re developing in Delphi and looking for a powerful, flexible, and highly customizable data grid solution, then TMS FNC Data Grid is the perfect choice. In this blog, we continue on our journey with the TMS FNC Data Grid. The TMS FNC Data Grid offers developers advanced tools for presenting and interacting with data. Master-Detail relationships is a feature to create intuitive and synchronized data representations, where a master grid shows parent records, and a detail grid reflects the corresponding child records based on the selected master entry.

Master-Detail

By linking the master and detail grids through the adapter, the detail grid can dynamically refresh and display the appropriate records from the child table. This is achieved by setting up datasets for both tables and using TDataSource components for database linking.

Setting up Master-Detail Tables

The master-detail relationship consists of:

  • Master Table: Contains parent records (e.g., `Orders`).
  • Detail Table: Contains child records linked to the master table (e.g., `OrderDetails` with a foreign key `OrderID`).

Configuring Database Components

  1. Create Datasets
    • Create datasets for the master (`Orders`) and detail (`OrderDetails`) tables.
    • Use `TDataSource` components to link the datasets (`dsMaster` and `dsDetail`).
  2. Configure Database Adapters
    • Place two `TTMSFNCDataGridDatabaseAdapter` components on the form.
    • Set the `DataSource` of `MasterAdapter` to `dsMaster` and `DetailAdapter` to `dsDetail`.

Linking Master and Details Grids

  1. Master Grid Setup
    • Drop a `TTMSFNCDataGrid` component on the form and set it to display fields from the master dataset (`Orders`).
    • Bind this grid to `MasterAdapter`.
  2. Detail Grid Setup
    • Add another `TTMSFNCDataGrid` for the detail dataset (`OrderDetails`).
    • Bind this grid to `DetailAdapter`.
  3. Define Master-Detail Relationship
    • Set the `MasterSource` property of the detail dataset (`dsDetail`) to the master dataset’s `TDataSource`.
    • Define the `MasterFields` to specify the linking key (e.g., `OrderID`).
  4. Display Detail Data:
    • Set the DetailControl property of the `MasterAdapter` to `OrderDetails` Grid
TMS Software Delphi  Components


Custom Detail

With TTMSFNCDataGrid, you have freedom of choice, and this also applies to setting up Master-Detail relationships. In this sample, we created a panel, added a TTMSFNCDataGrid instance which is bound to a detail table, and a chart, also setup via the same detail table.

TMS Software Delphi  Components

Conclusion

Master/Detail relationships are crucial for efficiently presenting data from multiple sources. The "Master" view provides a high-level summary, while the "Detail" section shows specific information for a selected item. This approach enhances user experience by allowing easy navigation of large datasets, improving clarity, and enabling efficient data exploration. It's ideal for applications needing flexible, scalable, and intuitive data management.

In the next blog we'll explore how you can add column & row calculations, so stay tuned for more advanced tips and tutorials on leveraging this next-generation data grid for your Delphi projects! Happy coding!



Pieter Scheldeman


  1. Next Generation Data Grid for Delphi: Getting Started

  2. Next Generation Data Grid for Delphi: Adding, Formatting & Converting Data

  3. Next Generation Data Grid for Delphi: Filtering & Sorting

  4. Next Generation Data Grid for Delphi: Grouping

  5. Next Generation Data Grid for Delphi: Webinar Replay Available!

  6. Next Generation Data Grid for Delphi: Cell Controls

  7. Next Generation Data Grid for Delphi: Master-Detail

  8. Next Generation Data Grid for Delphi: Calculations

  9. Next Generation Data Grid for Delphi: Import & Export

  10. Next Generation Data Grid for Delphi: Template

  11. Next Generation Data Grid for Delphi: Filter Row

  12. Next Generation Data Grid for C++: Getting Started



This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post