ComponentOne True DBGrid for WinForms
Specifying Text-to-Text Translations
Data Presentation Techniques > Automatic Data Translation with ValueItems > Specifying Text-to-Text Translations

Consider the following example, in which the Country field is represented by a short character code.

To display the character codes as proper names, use the column's ValueItemCollection object to specify automatic data translations. At design time, this is done with .NET's ValueItemCollection editor.

Altering the ValueItemCollection object through the collection editor enables you to specify data translations on a per-column basis in a simple window. To construct a list of data translations for an individual column, complete the following steps:

  1. Open up the C1TrueDBGrid Designer by clicking on the ellipsis button (…) next to the Columns collection in the Properties window.
  2. Select the column whose contents you would like translated. In the left pane expand the ValueItems node. Clicking on the ellipsis button next to the Values node will bring up the ValueItemCollection editor.
  3. In the right pane under the ValueItems node, set the Translate property to True.
  4. Clicking on the Add button in the left pane will add ValueItem objects. In the right pane specify a Value and DisplayValue for each ValueItem. When entering the ValueItem text, disregard the drop-down button. This is used for entering a bitmap as a DisplayValue.
  5. Select OK or Apply to commit the changes.

When the program is run, Country field values that match any items in the Value column appear as the corresponding DisplayValue entry. For example, CAN becomes Canada, UK becomes UnitedKingdom, and so on.

Note that the underlying database is not affected; only the presentation of the data value is different. The same effect can be achieved in code as follows:

To write code in Visual Basic

Visual Basic
Copy Code
Dim v as C1.Win.C1TrueDBGrid.ValueItemCollection
v = Me.C1TrueDBGrid1.Columns("Country").ValueItems.Values
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("CAN","Canada"))
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("UK","United Kingdom"))
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("USA","United States"))
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("JPN","Japan"))
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("AUS","Australia"))
Me.C1TrueDBGrid1.Columns("Country").ValueItems.Translate = True

To write code in C#

Copy Code
C1.Win.C1TrueDBGrid.ValueItemCollection v = this.c1TrueDBGrid1.Columns["Country"].ValueItems.Values;
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("CAN","Canada"));
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("UK","United Kingdom"));
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("USA","United States"));
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("JPN","Japan"));
v.Add(new C1.Win.C1TrueDBGrid.ValueItem("AUS","Australia"));
this.c1TrueDBGrid1.Columns["Country"].ValueItems.Translate = true;
See Also