When using a DataMap in an unbound FlexGrid to map numerical keys (e.g., 1, 2, 3) to user-friendly string labels (e.g., weekday names), the grid may continue displaying raw numeric keys instead of mapped text values.
Solution
This issue typically happens when the column's DataType does not match the data type of the keys stored in your dictionary collection. If the column's DataType is set to String while the keys in your ListDictionary or Dictionary are integers, the lookup fails to find matching key-value pairs.
To resolve this issue:
-
Match Data Types: Ensure the column's
DataTypeis explicitly set toGetType(Integer)so it aligns with the integer key types in your dictionary collection. -
Assign DataMap Directly: You can apply the
DataMapdirectly to the column usingColumn.DataMapor through a customCellStyle.
' Add column and set DataType to Integer to match the dictionary key type
With flexGrid.Cols.Add()
.Caption = "Weekday"
.Name = .Caption
.Width = 140
.DataType = GetType(Integer) ' Must match the Key data type in the dictionary
' Create a dictionary mapping integer keys to display values
Dim datamap As New ListDictionary()
datamap.Add(1, "Sunday")
datamap.Add(2, "Monday")
datamap.Add(3, "Tuesday")
datamap.Add(4, "Wednesday")
datamap.Add(5, "Thursday")
datamap.Add(6, "Friday")
datamap.Add(7, "Saturday")
' Approach 1: Assign DataMap directly to the Column
.DataMap = datamap
' Approach 2: Alternatively, assign DataMap via a CellStyle
' Dim style As CellStyle = flexGrid.Styles.Add("WeekdayStyle")
' style.DataMap = datamap
' .Style = style
End With