i just want to know how to display data in the listview.Here is my code:

Sub viewAttendance()
 da = New SqlDataAdapter("select AttendanceDate,TimeIn,TimeOut,LateMin from tbl_Attendance", con)
        'da.SelectCommand = cmd
        da.Fill(ds, "tbl_Attendance")
        'Dim krow1 As Integer = ds.Tables(0).Rows.Count

        With lvwAttendance
            .View = View.Details
            .FullRowSelect = True
            .GridLines = True
            .Columns.Add("Date", 100, HorizontalAlignment.Left)
            .Columns.Add("In Time", 150, HorizontalAlignment.Left)
            .Columns.Add("Out Time", 150, HorizontalAlignment.Left)
            .Columns.Add("Late Mins", 150, HorizontalAlignment.Left)
        End With

        Dim i As Integer
        Dim icol As Integer = ds.Tables(0).Columns.Count
        Dim k As Integer
        Dim krow As Integer = ds.Tables(0).Rows.Count
        Dim thisrow(icol) As String
        Dim j As Integer = 1

        For k = 0 To krow - 1
            For i = 0 To icol - 1
                thisrow(i) = ds.Tables(0).Rows(k).Item(i).ToString

            Dim lsvi As New ListViewItem(thisrow, 0)

            '//=Start Alternate Color
            If k / 2 <> Int(k / 2) Then '//=Determine Alternate Row(odd or not)
                lsvi.BackColor = Color.Lavender
                lsvi.BackColor = Color.White
            End If
            '//=End Alternate Color
            j = j + 1
    End Sub

    Private Sub btnview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnview.Click
        da = New SqlDataAdapter("select AttendanceDate,TimeIn,TimeOut,LateMin from tbl_Attendance", con)
        da.Fill(ds, "tbl_Attendance")
        Dim lv As ListView = lvwAttendance
        lv.Items(0) = ds.Tables(0).Rows(0).Item(1)
        lv.Items(0).SubItems(1) = ds.Tables(0).Rows(0).Item(2)
        lv.Items(0).SubItems(2) = ds.Tables(0).Rows(0).Item(3)
        lv.Items(0).SubItems(3) = ds.Tables(0).Rows(0).Item(4)

im getting an error like this " Unable to cast object of type 'System.String' to type 'System.Windows.Forms.ListViewItem'"

pls help me out.......

Edited 6 Years Ago by __avd: Added [code] tags.

Welcome to Daniweb. I have asked that your question be moved to .NET. I'm sure you will find the answer there.

This article has been dead for over six months. Start a new discussion instead.