how to inset auto increment column in list view?

hlsc1983

Member
Joined
Mar 6, 2014
Messages
8
Programming Experience
1-3
I am using the following sub to populate my list. i want to insert another column at run time to automatically number the records in the list view.therefore the numbering should start from 1 and 2,3,4,5 and so on. in other words i want to insert an auto increment column at run time and this column must be placed in the leftmost position.


VB.NET:
 Public Sub populate_lvw()
        lvw.Items.Clear()
        con.Close()

        con.Open()
        cmd = New SqlCommand("SELECT * FROM Students s  join (select  student_fullname, student_dob   from Students GROUP BY student_fullname, student_dob HAVING count(*) > 1) a on s.student_fullname = a.student_fullname and s.student_dob=a.student_dob order by s.student_fullname", con)
        Using dr As SqlDataReader = cmd.ExecuteReader

            If dr.HasRows Then
                While dr.Read
                    Dim li As New ListViewItem()
                    li.Text = Convert.ToString(dr.Item("student_slno"))
                    li.SubItems.Add(Convert.ToString(dr.Item("student_fullname")))
                    li.SubItems.Add(CType(dr.Item("student_dob"), DateTime).ToShortDateString)
                    'li.SubItems.Add(Convert.ToString(dr.Item("student_dob")))
                    li.SubItems.Add(Convert.ToString(dr.Item("student_branch")))
                    li.SubItems.Add(Convert.ToString(dr.Item("student_scholarship")))
                    li.SubItems.Add(Convert.ToString(dr.Item("student_accountno")))

                    '  li.SubItems.Add(dr.Item("student_dob")).ToString("dd/MM/yyyy")
                    lvw.Items.Add(li)
                End While

            Else : MsgBox(" No defaulters found", MsgBoxStyle.OkOnly)

            End If

        End Using
        cmd.Dispose()
        con.Close()


    End Sub
 
Back
Top