This is a migrated thread and some comments may be shown as answers.

Decimal column - how to display as unsigned integer

4 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lou
Top achievements
Rank 1
Lou asked on 25 Feb 2015, 07:27 PM
Hi, I am using the RadGridView to display a database column that is of type signed integer. However I want the column to display as an unsigned integer.
The grid column type that I'm using is GridViewDecimalColumn.

For example, the integer value (signed) is -1. Currently it shows up in the grid as -1, but I want it to display as 255.

How would I do this?

Thanks,

-Lou



4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Mar 2015, 12:10 PM
Hello Lou,

Thank you for writing.

It is appropriate to use a TypeConverter and specify the DataTypeConverter property for your specific column. Thus, you will be allowed to make the numeric conversion. Additionally, in the CellEditorInitialized event you can specify the initial editor's value. Please refer to the How to: Implement a Type Converter MSDN article which is wuite useful on this topic.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lou
Top achievements
Rank 1
answered on 05 Mar 2015, 07:13 PM
Hi Dess, thanks for the reply. I tried to get this to work but no luck. I created a TypeConverter that converted from Int32 to UInt32.
I assigned it to the DataTypeConverter property as you suggested. I ran the project with a breakpoint inside the new TypeConverter code to make sure it was being called. It never stopped inside this code.

In any case - after thinking a bit more I don't think I need to do this conversion - so am not going to pursue it further. Thanks again for the reply, if I come back to this and have any more questions I'll post again.
0
Dimitar
Telerik team
answered on 10 Mar 2015, 12:28 PM
Hello Lou,

Thank you for writing back.

I have created a quick test for this and it seems to be working as expected on my side. This is my code:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
        GridViewDecimalColumn col = new GridViewDecimalColumn();
        col.DataType = typeof(int);
        col.DataTypeConverter = new MyConverter();
 
        radGridView1.Columns.Add(col);
        radGridView1.Rows.Add(-1);
        radGridView1.Rows.Add(2);
    }
}
 
public class MyConverter : TypeConverter
{
    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
        return destinationType == typeof(uint);
    }
 
    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
    {
        return Convert.ToInt32((uint)value);
        //return base.ConvertTo(context, culture, value, destinationType);
    }
 
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
        return sourceType == typeof(int);
    }
 
    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        int val = (int)value;
        if (val <0)
        {
            return 255;
        }
        return Convert.ToUInt32((int)value);
        //return base.ConvertFrom(context, culture, value);
    }
}

I hope this will be useful. Should you have further questions, I would be glad to help.
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lou
Top achievements
Rank 1
answered on 10 Mar 2015, 01:07 PM
Hi Dimitar, thanks for creating that test.

-Lou
Tags
GridView
Asked by
Lou
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Lou
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or