Hello,
Let's suppose I have a large DB of vehicles. One of the tables is tblColors that has a numeric ColorCode and a string ColorName (say there's about a hundred of those).
The main table contains a ColorCode of the vehicle but I need to show ColorName in my grid. What I do is I create a TypeConverter that goes like
public
class
ColorConverter
{
public
object
Convert(
object
, Type,
object
, CultureInfo)
{
byte
? colorCode = value
as
byte
?;
swtich (colorCode)
{
case
1:
return
"White"
;
break
;
.....
}
........
}
Then I go to my grid and create a column:
...
<
Grid.Resources
>
<
r:ColorConverter
x:Key
=
"ColorConverter"
/>
</
Grid.Resources
>
...
<
telerik:RadGridView
Name
=
"myGrid"
AutoGenerateColumns
=
"false"
... >
<
telerik:RadGridView.Columns
>
...
<
telerik:GridViewDataColumn
Header
=
"Color"
DataMemberBinding
=
"{Binding ColorCode, Converter={StaticResource ColorConverter}}"
/>
...
</
telerik:RadGridViewColumns
>
...
</
telerik:RadGridView
>
First of all: am I doing this right? I don't want to query my other table on each row loading so I just preload (or hard-code) the code->name relation.
Second question is, now when I click on the filtering symbol for the Color column, I'm getting the numbers not the converted values. I could preload the values (as a List<String>) in the DistinctValuesLoading event but then when I'm trying to filter I'm getting a "System.FormatException: Input string was not in a correct format."
Thank you.