Decimal column - how to display as unsigned integer

5 posts, 0 answers
  1. Lou
    Lou avatar
    61 posts
    Member since:
    Aug 2014

    Posted 25 Feb 2015 Link to this post

    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



  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 02 Mar 2015 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Lou
    Lou avatar
    61 posts
    Member since:
    Aug 2014

    Posted 05 Mar 2015 in reply to Dess Link to this post

    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.
  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 10 Mar 2015 Link to this post

    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.

     
  6. Lou
    Lou avatar
    61 posts
    Member since:
    Aug 2014

    Posted 10 Mar 2015 in reply to Dimitar Link to this post

    Hi Dimitar, thanks for creating that test.

    -Lou
Back to Top
UI for WinForms is Visual Studio 2017 Ready