ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

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, do the following:

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 matches an item in the Value column appear as the corresponding DisplayValue entry. For example, CAN becomes Canada, UK becomes United Kingdom, and so forth.

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:

·      Visual Basic

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

·      C#

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;

·      Delphi

var item1: C1TrueDBGrid.ValueItem;

 

with Self.C1TrueDBGrid1.Columns['Country'] do

begin

  item1 := C1.Win.C1TrueDBGrid.ValueItem.Create;

  item1.Value :='CAN';

  item1.DisplayValue :='Canada';

  Add(item1);

  item1 := C1.Win.C1TrueDBGrid.ValueItem.Create;

  item1.Value :='UK';

  item1.DisplayValue :='United Kingdom';

  Add(item1);

  item1 := C1.Win.C1TrueDBGrid.ValueItem.Create;

  item1.Value :='USA';

  item1.DisplayValue :='United States';

  Add(item1);

  item1 := C1.Win.C1TrueDBGrid.ValueItem.Create;

  item1.Value :='JPN';

  item1.DisplayValue :='Japan';

  Add(item1);

  item1 := C1.Win.C1TrueDBGrid.ValueItem.Create;

  item1.Value :='AUS';

  item1.DisplayValue :='Australia';

  Add(item1);

  Self.C1TrueDBGrid1.Columns['Country'].ValueItems.Translate := True;

end;


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.