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

Nullable Guid throwing exception

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vlatko
Top achievements
Rank 1
Vlatko asked on 19 Dec 2008, 10:23 AM
GridColumn column = new GridBoundColumn(); 
if (RadGrid.IsBindableType(typeof(Guid?))) 
    column.DataType = typeof(Guid?); 
Trying to do something like this will throw exception "Specified column DataType is not supported System.Nullable`1[System.Guid]". Couldn't find anything about this problem on forum and looking at documentation Guid is supported and nullable types are also. Since IsBindableType returns true I think this may be a bug. Version of Telerik.Web.Ui.dll I was using is 2008.1.625.20.
 

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 19 Dec 2008, 02:26 PM
Hello Vlatko,

If you need to have null value in a GridColumn you do not have to set it's type as Nullable. In the case in question you may try setting column's type just as type of Guid.

Please give it a try and let us know if this helps.

Regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vlatko
Top achievements
Rank 1
answered on 19 Dec 2008, 04:24 PM
This is ok, but when columns are dynamically created this can be problem. I can isolate Guid?, but what next type I can expect will throw exception again? If I use method RadGrid.IsBindableType to check if type is bindable and next thing when I try to set that type I get exception is a bug to me. I can put silent throw catch, but that is not really nice solution. Also if I change version in future where you may add or remove support for some types It can potentially cause exception again.
0
Rosen
Telerik team
answered on 22 Dec 2008, 09:09 AM
Hi Vlatko,

The error you are getting is thrown by the DataTable which is used internally by RadGrid control. As the DataTable do not support nullable types. Thus you should not set column's DataType property to be a Nullable type but you should set them to its underlining type. You may use a simple method as the following in order to extract the type of the object and assign is to the GridColumn's DataType properties.

protected Type GetType<T>(T value)  
    {  
        Type type = typeof (T);  
        if (value is Nullable ||   
                (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)))  
        {  
            return Nullable.GetUnderlyingType(type);   
        }  
        return type;  
    } 

All the best,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Vlatko
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Vlatko
Top achievements
Rank 1
Share this question
or