none
DateFormat in year only appear two digits instead of four in ListView vb.net

    Question

  • With Binding the Listview with dataset, the dateformat in datefield only appear the year as '12' instead of '2012',

    strSQL = "select * from tableA where PNo = '" & cbPortNo.SelectedItem.ToString() & "' and convert(date, fDateReceived) = '" & dDateSelected & "'"
    
                Dim da1 As New SqlDataAdapter(strSQL, sqlconn)
                da1.Fill(ds)
    
                If (ds.Tables(0).Rows.Count > 0) Then
    
                    ShowDataInLvwReadMsg(ds.Tables(0), ListView2)
    
    
    
     Private Sub ShowDataInLvwReadMsg(ByVal data As DataTable, ByVal lvw As ListView)
            lvw.View = View.Details
            lvw.GridLines = True
            lvw.Columns.Clear()
            lvw.Items.Clear()
            For Each col As DataColumn In data.Columns
                lvw.Columns.Add(col.ToString)
            Next
    
            For Each row As DataRow In data.Rows
                Dim lst As ListViewItem
                lst = lvw.Items.Add(row(0))
                For i As Integer = 1 To data.Columns.Count - 1
    
    
    
                    If (IsDBNull(row(i))) Then
    
                        lst.SubItems.Add(" ")
    
                    Else
    
                        lst.SubItems.Add(row(i))
    
                    End If
    
    
                Next
            Next
    
            lvw.Columns(1).Width = 50
            lvw.Columns(2).Width = 150
            lvw.Columns(3).Width = 150
            lvw.Columns(4).Width = 300
            lvw.Columns(5).Width = 150
    
            lvw.Columns(0).Dispose()
    
    
        End Sub

    Friday, May 18, 2012 7:19 AM

Answers

  • got it already

    If (IsDBNull(row(i))) Then
    
                        lst.SubItems.Add(" ")
    
                    Else
    
                        If (data.Columns(i).DataType Is GetType(Date)) Then
                            lst.SubItems.Add(Format(row(i), "dd\/MM\/yyyy hh:mm:ss.ttt"))
                        Else
                            lst.SubItems.Add(row(i))
                        End If
    
                    End If

    • Marked as answer by learner08 Friday, May 18, 2012 8:33 AM
    Friday, May 18, 2012 8:32 AM

All replies

  • You cannot bind a listview to a dataset. 

    You can set the idividual items but that is not binding. 

    Why not use simply a DataGridView instead of this almost impossible to handle dinosaur method?


    Success
    Cor

    Friday, May 18, 2012 7:22 AM
  • got it already

    If (IsDBNull(row(i))) Then
    
                        lst.SubItems.Add(" ")
    
                    Else
    
                        If (data.Columns(i).DataType Is GetType(Date)) Then
                            lst.SubItems.Add(Format(row(i), "dd\/MM\/yyyy hh:mm:ss.ttt"))
                        Else
                            lst.SubItems.Add(row(i))
                        End If
    
                    End If

    • Marked as answer by learner08 Friday, May 18, 2012 8:33 AM
    Friday, May 18, 2012 8:32 AM