I have to format a string ("00:10:08:10") into (10 weeks 08 days 10 hrs). So I used a converter and added it with the datagrid binding. My code:
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Dim strList(4) As String
Dim prefixList() As String = {"Wk", "Dy", "Hrs", "Min"}
Dim input As String = value.ToString
Dim Output As String = String.Empty
If input <> String.Empty Then
strList = input.Split(":")
Dim itr As Integer
For Each Str As String In strList
If Integer.Parse(Str) <> 0 Then
Output += Str + " " + prefixList(itr) + " "
End If
itr += 1
Next
End If
Return Output
End Function
I am getting it converted but when I edit the data, the converter is called again where I wouldn't have the old format("00:10:08:10") and instead its (10 Dy 08 Hr 10 Min). so the converter fails obviously. How can I make it work?
Additional: And is there a data type in mssql to represent my data in days and hours so that i wont have to use this string format.