dbgrid seleção

08/03/2003

0

Olá!

Gostaria de saber se há como selecionar um registro em um dbgrid e fazer com que em outro dbgrid apareça um registro correspondente ao item selecionado. E como poderia fazer isso.

Obrigado!


Anonymous

Anonymous

Responder

Posts

08/03/2003

Aroldo Zanela

Olá! Gostaria de saber se há como selecionar um registro em um dbgrid e fazer com que em outro dbgrid apareça um registro correspondente ao item selecionado. E como poderia fazer isso. Obrigado!


Os seguintes passos cria um formulário simples em que o usuário pode rolar entre os registros de clientes e mostrar todas as suas compras.

A tabela mestre é a CustomersTable e a tabela detalhe é OrdersTable.

Tá no help!!! Se enrroscar avisa...

[list:e0f03432fb]
The following steps create a simple form in which a user can scroll through customer records and display all orders for the current customer. The master table is the CustomersTable table, and the detail table is OrdersTable.

1Place two TTable and two TDataSource components in a data module.
2Set the properties of the first TTable component as follows:

DatabaseName: DBDEMOS
TableName: CUSTOMER
Name: CustomersTable

3Set the properties of the second TTable component as follows:

DatabaseName: DBDEMOS
TableName: ORDERS
Name: OrdersTable

4Set the properties of the first TDataSource component as follows:

Name: CustSource
DataSet: CustomersTable

5Set the properties of the second TDataSource component as follows:

Name: OrdersSource
DataSet: OrdersTable

6Place two TDBGrid components on a form.
7Choose File|Include Unit Hdr to specify that the form should use the data module.
8Set the DataSource property of the first grid component to
“DataModule2->CustSource”, and set the DataSource property of the second grid to “DataModule2->OrdersSource”.
9Set the MasterSource property of OrdersTable to “CustSource”. This links the CUSTOMER table (the master table) to the ORDERS table (the detail table).

10Double-click the MasterFields property value box in the Object Inspector to invoke the Field Link Designer to set the following properties:

In the Available Indexes field, choose CustNo to link the two tables by the CustNo field.
Select CustNo in both the Detail Fields and Master Fields field lists.
Click the Add button to add this join condition. In the Joined Fields list,
“CustNo -> CustNo” appears.
Choose OK to commit your selections and exit the Field Link Designer.

11Set the Active properties of CustomersTable and OrdersTable to True to display data in the grids on the form.
12Compile and run the application.

If you run the application now, you will see that the tables are linked together, and that when you move to a new record in the CUSTOMER table, you see only those records in the ORDERS table that belong to the current customer.
[/list:u:e0f03432fb]


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar