CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2009
    Posts
    192

    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

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Change Date format in List view

    Have you tried using the Format function ¿

  3. #3
    Join Date
    Feb 2009
    Posts
    192

    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
    Last edited by HanneSThEGreaT; August 5th, 2009 at 10:43 AM. Reason: Code Tags!

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Change Date format in List view


  5. #5
    Join Date
    Feb 2009
    Posts
    192

    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
    Last edited by HanneSThEGreaT; August 5th, 2009 at 11:09 AM. Reason: Code Tags!

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Change Date format in List view

    Try this :
    Code:
    MyStr = Format(LvwColProc.Items(0).SubItems(2).Text, "d-mm-yyyy")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured