hi

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)
        ds.Tables.Clear()
        'da.SelectCommand = cmd
        da.Fill(ds, "tbl_Attendance")
        'Dim krow1 As Integer = ds.Tables(0).Rows.Count

        With lvwAttendance
            .Clear()
            .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
            Next

            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
            Else
                lsvi.BackColor = Color.White
            End If
            '//=End Alternate Color
            j = j + 1
            lvwAttendance.Items.Add(lsvi)
        Next
        lvwAttendance.Sort()
    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)
        viewAttendance()

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

pls help me out.......

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.