Consider the following example in which the Country field is represented by a short character code:
To display the character codes as proper names, you can use the column's ValueItemCollection object to specify automatic data translations. At design time, this is done with .NET's ValueItem Collection 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:
When the program is run, Country field values that match 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:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim Item As C1.Win.C1List.ValueItem With Me.C1List1.Columns("Country").ValueItems.Values Item = New C1.Win.C1List.ValueItem() Item.Value = "CAN" Item.DisplayValue = "Canada" .Add(Item) Item = New C1.Win.C1List.ValueItem() Item.Value = "UK" Item.DisplayValue = "United Kingdom" .Add(Item) Item = New C1.Win.C1List.ValueItem() Item.Value = "USA" Item.DisplayValue = "United States" .Add(Item) Item = New C1.Win.C1List.ValueItem() Item.Value = "JPN" Item.DisplayValue = "Japan" .Add(Item) Item = New C1.Win.C1List.ValueItem() Item.Value = "AUS" Item.DisplayValue = "Australia" .Add(Item) Me.C1List1.Columns("Country").ValueItems.Translate = True End With |
To write code in C#
C# |
Copy Code
|
---|---|
C1.Win.C1List.ValueItem Item; C1.Win.C1List.ValueItem Item = new C1.Win.C1List.ValueItem(); C1.Win.C1List.ValueItemCollection values = this.c1List1.Columns[0].ValueItems.Values; Item.Value = "CAN"; Item.DisplayValue = "Canada"; values.Add(Item); Item = new C1.Win.C1List.ValueItem(); Item.Value = "UK"; Item.DisplayValue = "United Kingdom"; values.Add(Item); Item = new C1.Win.C1List.ValueItem(); Item.Value = "USA"; Item.DisplayValue = "United States"; values.Add(Item); Item = new C1.Win.C1List.ValueItem(); Item.Value = "JPN"; Item.DisplayValue = "Japan"; values.Add(Item); Item = new C1.Win.C1List.ValueItem(); Item.Value = "AUS"; Item.DisplayValue = "Australia"; values.Add(Item); this.c1List1.Columns["Country"].ValueItems.Translate = true; |