The second way to add type converters is to use the TypeConverterAttribute, which allows you to specify the TypeConverter for any property in your business object. Private Sub ConvertingDataTypes_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Loadĭim checkBox As New GridViewCheckBoxColumn("Organic", "IsOrganic")ĬheckBox.DataTypeConverter = New ToggleStateConverter()Īpplying to the incompatible property of the business object used as a data source GridViewCheckBoxColumn checkBox = new GridViewCheckBoxColumn("Organic", "IsOrganic") ĬheckBox.DataTypeConverter = new ToggleStateConverter() Private void ConvertingDataTypes_Load(object sender, EventArgs e) This approach is handy when you using non-business objects (such as DataTable) or your business objects’ properties do not have TypeConverterAttribute applied. The first approach to apply type converters is to create the desired column and assign its DataTypeConverter property. Setting the DataTypeConverter property of the column There are two ways to apply converters to the RadGridView conversion layer: Return MyBase.ConvertFrom(context, culture, value) Public Overrides Function ConvertFrom(context As ITypeDescriptorContext, culture As CultureInfo, value As Object) As Object Return sourceType Is GetType(ToggleState) OrElse sourceType Is GetType(Boolean) Public Overrides Function CanConvertFrom(context As ITypeDescriptorContext, sourceType As Type) As Boolean Return MyBase.ConvertTo(context, culture, value, destinationType) If TypeOf value Is Char AndAlso destinationType Is GetType(ToggleState) ThenĮlseIf TypeOf value Is Boolean AndAlso destinationType Is GetType(Char) Then Public Overrides Function ConvertTo(context As ITypeDescriptorContext, culture As CultureInfo, value As Object, destinationType As Type) As Object Return destinationType Is GetType(ToggleState) OrElse destinationType Is GetType(Boolean) Public Overrides Function CanConvertTo(context As ITypeDescriptorContext, destinationType As Type) As Boolean Return base.ConvertFrom(context, culture, value) Public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) Return sourceType = typeof(ToggleState) || sourceType = typeof(bool) Public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) Return base.ConvertTo(context, culture, value, destinationType) If (value is char & destinationType = typeof(ToggleState))Įlse if (value is bool & destinationType = typeof(char)) Public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) Return destinationType = typeof(ToggleState) || destinationType = typeof(bool) Public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) Public class ToggleStateConverter : TypeConverter
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |