ComponentOne True DBGrid Pro 8
Automatic data translation with TDBDropDown

Suppose that you need a grid drop-down using data which contains a value and a corresponding text representation, as in the following figure:

In this situation, you may not want the user to see the somewhat ambiguous TypeId, but instead want the more understandable TypeDesc to show in the drop-down. The ValueTranslate property automatically maps the TypeId value to the TypeDesc representation. In this way, when the user accesses the drop-down, it will display the TypeDesc text.

The steps to perform the drop-down auto value translation can all be done without code, using the data control properties, the True DBGrid property pages and the True DBDropDown property pages. To produce a drop-down using the auto value translation, perform the following steps:

1.   Place two data controls (VB Data Control, ADODC, or True DataControl), a True DBGrid control and a True DBDropDown control on a form.

2.   Connect one of the data controls to the C:\Program Files\ComponentOne Studio\Common\TDBG8DEMO.MDB database table and set the RecordSource property to Customers. Then connect the True DBGrid to this data control by choosing it in the DataSource property.

3.   Connect second data control to the C:\Program Files\ComponentOne Studio\Common\TDBG8DEMO.MDB database and set the RecordSource property to CustType. Then connect the True DBGrid to this data control by choosing it in the DataSource property.

4.   Retrieve the fields for both the grid and the drop-down controls by right clicking on each and selecting Retrieve Fields from the context menu.

5.   Go to the TDBDropDown1 properties page, set DataField property to TypeID, the ListField property to TypeDesc and the ValueTranslate property to True.

6.   Go to the TDBGrid1 properties page and choose the Splits tab. Expand the Splits(00) tree, then the Columns tree then the Columns(06) [CustType] tree. Set the Order property to 1, the AutoCompletion property to True, the AutoDropDown property to True and the Width property to 1300. Press Apply.

7.   Choose the General tab in TDBGrid1 properties page. Expand the Columns tree then the Columns(06) [CustType] tree. Set the DropDown property to TDBDropDown1. Press OK to accept the changes and close the property pages.

8.   Go to the TDBDropDown1 properties. On the General tab, expand the Columns tree then the Columns(00) [TypeID] tree. Set the Visible property to False. Press OK to accept the changes and close the property pages.

9.   Run the program. The True DBGrid should look like this.

For more information, see Drop-down Controls and Tutorial 26.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback