Hi my approach is to store model's translation by using DisplayAttributes,
for example
class XYZ{
[Display(Name =
"MyDisplayName"
,
ResourceType=
typeof
(MyResourceFileName))]
public
String ArbitrationLong
{
get
;
set
;
}
///...
}
then on the resource file MyResourceFileName add the properties translation.
the above tecnique is quite useful, many tools automatically interpret
them correctly, if you will use your class on an ASP.NET MVC all the helpers will automatically translate your labels, and also the telerik kendo ui grid is able to
automatically use the correct grid header if your model have such
attributes.
To return to telerik grid on winforms, at the time i don't think the telerik grid for winforms is automatically able to use the model's attributes, but you just need the above snippet they are few lines of code : It works for ITypedList datasources, otherwise you could retrieve the properties using reflection, what you have to modify is the first row on the above snippet all the other code remain the same, you can store the above snipped in any static function and call it as is, it needs a list of properties and a grid as parameters.
var props = (TheList
as
ITypedList).GetItemProperties(
null
);
foreach
(var column
in
theGrid.Columns)
{
var cprop = props.Find(column.FieldName,
true
);
if
(cprop !=
null
)
{
var display = cprop.Attributes.OfType<DisplayAttribute>().FirstOrDefault();
if
(display !=
null
)
{
if
(display.ResourceType ==
null
)
column.HeaderText = display.Name;
else
{
var dprop = display.ResourceType.GetProperty(display.Name, BindingFlags.Public | BindingFlags.Static);
if
(dprop ==
null
)
column.HeaderText = display.Name;
else
column.HeaderText = dprop.GetValue(
null
,
null
).ToString();
}
}
}
}
Best Regards