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

The same techniques used to specify text-to-text translations can also be used for text-to-picture translations. Within the ValueItem Collection Editor, instead of typing a string into the DisplayValue column, use the ellipsis button (...) to select a bitmap to be used for data translations. To delete your bitmap selection, simply delete the text in the DisplayValue property box and either select another bitmap or type in text.


Note that the Translate property for the ValueItems object must be set to True. Depending upon the height of the bitmaps, it may be necessary to increase the value of the RowHeight property. If that is done, change the VerticalAlignment member of the grid's Style property to Center to ensure that the bitmaps (as well as textual data in other columns) are centered vertically within grid cells instead of being anchored at the top.

When the program is run, Country field values that match an item in the Value column appear as the corresponding DisplayValue picture:


As with textual translations, 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.C1TrueDBGrid.ValueItem = New C1.Win.C1TrueDBGrid.ValueItem()
With Me.C1TrueDBGrid1.Columns("Country").ValueItems.Values
    Item.Value = "CAN"
    Item.DisplayValue = System.Drawing.Image.FromFile("canada.bmp")
    .Add(Item)
 
    Item = New C1.Win.C1TrueDBGrid.ValueItem()
    Item.Value = "UK"
    Item.DisplayValue = System.Drawing.Image.FromFile("uk.bmp")
    .Add(Item)
 
    Item = New C1.Win.C1TrueDBGrid.ValueItem()
    Item.Value = "USA"
    Item.DisplayValue = System.Drawing.Image.FromFile("usa.bmp")
    .Add(Item)
 
    Item = New C1.Win.C1TrueDBGrid.ValueItem()
    Item.Value = "JPN"
    Item.DisplayValue = System.Drawing.Image.FromFile("japan.bmp")
    .Add(Item)
 
    Item = New C1.Win.C1TrueDBGrid.ValueItem()
    Item.Value = "AUS"
    Item.DisplayValue = System.Drawing.Image.FromFile("australia.bmp")
    .Add(Item)
 
    Me.C1TrueDBGrid1.Columns("Country").ValueItems.Translate = True
End With

To write code in C#

C#
Copy Code
C1.Win.C1TrueDBGrid.ValueItemCollection v = this.c1TrueDBGrid.Columns["Country"].ValueItems.Values;
C1.Win.C1TrueDBGrid.ValueItem Item = new C1.Win.C1TrueDBGrid.ValueItem();
 
    Item.value = "CAN";
    Item.DisplayValue = System.Drawing.Image.FromFile["canada.bmp"];
    v.Add[Item];
 
    Item = new C1.Win.C1TrueDBGrid.ValueItem();
    Item.value = "UK";
    Item.DisplayValue = System.Drawing.Image.FromFile["uk.bmp"];
    v.Add[Item];
 
    Item = new C1.Win.C1TrueDBGrid.ValueItem();
    Item.value = "USA";
    Item.DisplayValue = System.Drawing.Image.FromFile["usa.bmp"];
    v.Add[Item];
 
    Item = new C1.Win.C1TrueDBGrid.ValueItem();
    Item.value = "JPN";
    Item.DisplayValue = System.Drawing.Image.FromFile["japan.bmp"];
    v.Add[Item];
 
    Item = new C1.Win.C1TrueDBGrid.ValueItem();
    Item.value = "AUS";
    Item.DisplayValue = System.Drawing.Image.FromFile["australia.bmp"];
    v.Add[Item];
 
    this.c1TrueDBGrid1.Columns["Country"].ValueItems.Translate = true;
See Also