top of page

Using a FirePower LookupCombo in a DataGrid



Today we are going to talk about one of the most useful components in FirePower, the TwwLookupComboEdit. This component allows you to display values generated from a related table in a dropdown list, and then after the user makes a selection the value is filled into the edited data source. Here is a screenshot of what we are going to accomplish today. We will embed the LookupCombo in a FirePower grid.


Since we are going to do this in a grid, it will be a 3 step process. Here is a summary of the steps we will be going over.

  1. Setting up the grid to use the Orders table in our database

  2. Setting up the grid to display the descriptive text (Company Name) from our CustomerTable

  3. Associating a LookupComboEdit control with the lookupfield in the grid.

Below is the finished project where you can see what this will look like at the end of this blogpost:

https://github.com/roywoll/FirePowerDemos



Setting up the grid to use the Orders table in our database

To see this, let us quickly set up a demo using a TwwDataGrid. We are going to use our FirePower sqlite demo database for this.

1. Drop in a TFDConnection, and 2 TFDTables. Name the first TFDTable as OrdersTable, and the second TFDTable as CustomersTable, and the TFDConnection as FPConnection

2. Set up the database connection

a. Dbl-click the FPConnection object and dropping down the combo labelled Connection Definition Name and selecting FirePowerSQLLite. Please note that this selection is only available after you have installed FirePower Trial or Release version.

b. Now click the Test Connection button to make sure the connection is working. After confirming, then click ok to close the dialog.

c. Click on FPConnection and set LoginPrompt to false so we don’t have to keep entering our credentials. Also you can set FPConnection.Connected to True.

3. Connect your tables we will be using

a. Select OrdersTable and select the TableName as Orders. 
b. Select CustomersTable and select the TableName as fdCustomer. Also set the FormatOptions.SortLocale to 0. Otherwise you may get duplicate records during incremental searching.

4. Create bindsources for your tables by right-clicking each one and selecting Add BindSource. We need these in order to connect our grid to the tables. Name the bindsource connected to the OrdersTable as bsOrders, and the bindsource connected to the CustomersTable as bsCustomers

5. Activate your tables by setting their Active property to true.

6. Drop in a TwwDataGrid and then set its DataSource property to bsOrders. Now let us align the grid, by setting Align to alClient. After this step, our form should like like this.

In this grid we are displaying a list of orders. We assume our OrdersTable is normalized, meaning it does not contain redundant information from a related table. What we would like to do is to lookup an existing customer and fill the Customer No into the OrdersTable. Even better, we would like to lookup and display using a more meaning descriptive name (such as Company Name), but then fill in the CustomerNo value internally without requiring the user to enter this. This allows us to use a normalized database.