-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyConverter.vb
52 lines (49 loc) · 2.18 KB
/
MyConverter.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Imports DevExpress.Spreadsheet
Imports System
Imports System.Collections.Generic
Imports System.Linq
Namespace DataBindingToListExample
#Region "#MyWeatherConverter"
Public Class MyWeatherConverter
Implements IBindingRangeValueConverter
Public Function ConvertToObject(ByVal value As CellValue, ByVal requiredType As Type, ByVal columnIndex As Integer) As Object Implements IBindingRangeValueConverter.ConvertToObject
If requiredType Is GetType(Date) Then
Return value.DateTimeValue
End If
If requiredType Is GetType(Weather) Then
If requiredType Is GetType(Weather) Then
Dim w As Weather = Nothing
If System.Enum.TryParse(value.TextValue, w) Then
Return w
End If
Return Weather.Undefined
Else
Return value.TextValue
End If
End If
If requiredType Is GetType(List(Of HourlyReport)) Then
Return New List(Of HourlyReport)()
End If
Return value.TextValue
End Function
Public Function TryConvertFromObject(ByVal value As Object) As CellValue Implements IBindingRangeValueConverter.TryConvertFromObject
If TypeOf value Is Date Then
Return DirectCast(value, Date).ToString("MMM-dd")
End If
If TypeOf value Is Weather Then
Return value.ToString()
End If
If TypeOf value Is List(Of HourlyReport) Then
Dim hourly = DirectCast(value, List(Of HourlyReport))
If hourly.Count = 0 Then
Return "Undefined"
End If
Dim high = hourly.OrderByDescending(Function(p) p.Temperature).FirstOrDefault().Temperature
Dim low = hourly.OrderBy(Function(p) p.Temperature).FirstOrDefault().Temperature
Return String.Format("High - {0}, Low - {1}", high, low)
End If
Return CellValue.TryCreateFromObject(value)
End Function
End Class
#End Region ' #MyWeatherConverter
End Namespace