Tutorials > Tutorial 7 - Displaying Translated Data with the Built-in Combo |
In this tutorial, you will learn how to use the ValueItems collection to display translated text and enable the grid's built-in drop-down combo for editing—all without writing a single line of code.
Start with the project created in Tutorial 6.
Right-click TDBGrid1 to display its context menu.
Choose Properties to display the Property Pages dialog. Select the Values property page by clicking the Values tab. This property page is used to specify the ValueItems collection associated with a column.
Drop down the Column combo box and select Column1 (CustType).
Check the Translate box to instruct the grid to translate the data in Column1 before displaying it. Note that the grid at the bottom of the property page now displays two columns labeled Value and DisplayValue.
Drop down the Presentation combo box and select 2 - Combo Box. This instructs the grid to display a combo box in Column1 when requested.
Now enter the Value - DisplayValue pairs in the grid as follows:
Example Title |
Copy Code
|
---|---|
Value Display Value 1 Prospective 2 Normal 3 Buyer 4 Distributor 5 Other |
Entries in the Value column are data values from the CustType field in the database table. The grid treats the Value property as a string. Entries in the DisplayValue column are translated values to be displayed in the CustType column of the grid. For example, a CustType of 1 will be displayed as Prospective, 2 will be displayed as Normal, and so forth.
Note: Some databases store numbers with a leading space character to hold the place of a minus sign, so it may be necessary to prefix Value column entries with a space.
When you are finished entering data, the Values property page should look like this.
Click the OK button at the bottom of the Property Pages dialog to accept the changes.
Run the program and observe the following:
TDBGrid1 displays data from the joined tables as in Tutorial 6.
The CustType column now displays the translated text instead of numeric values.
Click a cell in the CustType column to make it the current cell. Notice that a drop-down button appears at the right edge of the cell.
Click the drop-down button or press Alt+Down Arrow to display the built-in combo box containing translated values, as shown in the following figure. You can change the data in the current cell by selecting the desired item from the combo box.
This concludes Tutorial 7.