Change Date format in List view
Hallo,
I have a date format on my list view which is read from sql server , i.e., the date format is expressed as for example 12/08/2009 12:00:00
I dont want to show the 12:00:00 at the front end level. At runtime the user will only see for example 12/08/2009 ONLY. How can I achieve that with the details shown below. Just need to format the SubItems(2) as it contains the date...
LvwColProc.Items(0).SubItems(2).Text
Thanks in advance.
Regards
Re: Change Date format in List view
Have you tried using the Format function ¿
Re: Change Date format in List view
nop
I have the followung sub where I need to insert the format function but I dont know the syntax,
Code:
Private Sub PopulateListViewColProc()
Me.LvwColProc.Items.Clear()
For Each com As ColProc In mColProc
Dim item As New ListViewItem()
PopulateListViewItemColproc(item, com)
Me.LvwColProc.Items.Add(item)
TxtCurrProcStage.Text = LvwColProc.Items(0).SubItems(1).Text
If (LvwColProc.Items(0).SubItems(2).Text = "01/01/1900") Or (LvwColProc.Items(0).SubItems(2).Text = "01/01/2025") Then
LvwColProc.Items(0).SubItems(2).Text = ""
End If
Next
End Sub
Re: Change Date format in List view
Re: Change Date format in List view
Thanks, tried the following code it gives an error;
Unable to cast object of type 'ListViewSubItem' to type 'System.IConvertible'.
How can I adjust the code...
Code:
Private Sub PopulateListViewColProc()
Me.LvwColProc.Items.Clear()
For Each com As ColProc In mColProc
Dim item As New ListViewItem()
PopulateListViewItemColproc(item, com)
Me.LvwColProc.Items.Add(item)
TxtCurrProcStage.Text = LvwColProc.Items(0).SubItems(1).Text
If (LvwColProc.Items(0).SubItems(2).Text = "01/01/1900") Or (LvwColProc.Items(0).SubItems(2).Text = "01/01/2025") Then
LvwColProc.Items(0).SubItems(2).Text = ""
End If
Dim MyDateTime As Date = #1/27/2001 5:04:23 AM#
Dim MyStr As String
'Also returns current system date in the system-defined long date
' format, using the single letter code for the format.
MyStr = Format(LvwColProc.Items(0).SubItems(2), "d-mm-yyyy")
Next
End Sub
Re: Change Date format in List view
Try this :
Code:
MyStr = Format(LvwColProc.Items(0).SubItems(2).Text, "d-mm-yyyy")