To reproduce:
- Use a column with numbers stored as strings.
- Set the data type to decimal
- The columns should be sorted according to the number value not alphabetically.
Workaround:
var col = new GridViewTextBoxColumn();
col.DataTypeConverter = new DecimalConverter();
col.FieldName = "Dosage";
col.UseDataTypeConverterWhenSorting = true;
col.DataType = typeof(decimal);
radGridView1.Columns.Add(col);
public class DecimalConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destination_type)
{
if (destination_type == typeof(decimal))
{
return true;
}
return base.CanConvertTo(context, destination_type);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destination_type)
{
if (destination_type == typeof(decimal))
{
return decimal.Parse(value.ToString());
}
return base.ConvertTo(context, culture, value, destination_type);
}
}