Hi i'm trying to understand how to use TypeConverters with databound columns.
The databound type is Int and I want to display a picture in a GridViewImageColumn based on that, but I can't make it work, the TypeConverter is never used by the RadGridView to convert the data?
Code:
TypeDescriptor.AddAttributes(typeof(int), new TypeConverterAttribute(
typeof(SeverityImageConverter)));
GridViewImageColumn Severity = new GridViewImageColumn("Severity", "Severity");
Severity.DataTypeConverter = TypeDescriptor.GetConverter(typeof(int));
IssueOverviewGrid.MasterTemplate.Columns.Add(Severity);
IssueOverviewGrid.DataSource = MasterBindingSource;
Type converter implementation:
public class SeverityImageConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(int))
return true;
else
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
// if no value passed along
if (value == null)
throw new ArgumentNullException("value");
// if the source is a string then convert to our type
if (value is int)
{
// get strongly typed value
int? SeverityValue = value as int?;
Image SeverityImage = Library.GetIssueSeverityIcon(SeverityValue.Value);
return SeverityImage;
}
// otherwise call the base converter
else
return base.ConvertFrom(context, culture, value);
}
}