Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Sub loadlistview()
        ListView1.Items.Clear()
        ListView1.Columns.Clear()
        Me.ListView1.View = View.Details
        Me.ListView1.GridLines = True
        Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=TrackingUnitsInventorySystem;Integrated Security=True")
        conn.Open()
        ListView1.Items.Clear()
        ListView1.Columns.Clear()
        Dim cmd As New SqlCommand("SELECT * from vUnit", conn)
        cmd.CommandType = CommandType.Text
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        Me.ListView1.Columns.Add("IMEI No")
        Me.ListView1.Columns(0).Width = 150
        Me.ListView1.Columns.Add("Status")
        Me.ListView1.Columns(1).Width = 100
        Me.ListView1.Columns.Add("Category")
        Me.ListView1.Columns(2).Width = 100
        Me.ListView1.Columns.Add("Origin")
        Me.ListView1.Columns(3).Width = 150
        Me.ListView1.Columns.Add("Warranty")
        Me.ListView1.Columns(4).Width = 150
        Me.ListView1.Columns.Add("PurchaseDate")
        Me.ListView1.Columns(5).Width = 150
        Me.ListView1.Columns.Add("Company")
        Me.ListView1.Columns(6).Width = 100
        Me.ListView1.Columns.Add("PurchaseOrder")
        Me.ListView1.Columns(7).Width = 150
        Me.ListView1.Columns.Add("AlternateCode")
        Me.ListView1.Columns(8).Width = 100
        Me.ListView1.Columns.Add("InnvoiceNo")
        Me.ListView1.Columns(9).Width = 100
        Me.ListView1.Columns.Add("Remarks")
        Me.ListView1.Columns(10).Width = 100
        Me.ListView1.Columns.Add("Total Units")
        Me.ListView1.Columns(11).Width = 100
        While reader.Read()
            Dim NewItem As New ListViewItem
            With NewItem
                .Text = reader("IMEINo").ToString
                With .SubItems
                    .Add(reader("Status").ToString)
                    .Add(reader("Category").ToString)
                    .Add(reader("Origin").ToString)
                    .Add(reader("Warranty").ToString)
                    .Add(reader("PurchaseDate").ToString)
                    .Add(reader("Company").ToString)
                    .Add(reader("PurchaseOrder").ToString)
                    .Add(reader("AlternateCode").ToString)
                    .Add(reader("InnvoiceNo").ToString)
                    .Add(reader("Remarks").ToString)
                    .Add(reader("Total").ToString)
                    ListView1.Items.Add(NewItem)
                End With
            End With

        End While
        reader.Close()
        conn.Close()
        NumberList()

    End Sub
Posted
Updated 8-Apr-13 5:48am
v2
Comments
CHill60 8-Apr-13 8:56am    
What IS the problem - you haven't asked a question yet
CPallini 8-Apr-13 11:50am    
Could you please elaborate the observed problem of you code?

1 solution

Pfhew that was difficult to read. Please use the code tags next time.

Anyway: I don't know if it helps but I'm pretty sure the
VB
listview1.items.add(newitem)
should not be inside the With statement.

You're also calling
VB
ListView1.Items.Clear()
ListView1.Columns.Clear()

twice.
 
Share this answer
 
Comments
Zubair Lohani 9-Apr-13 2:29am    
How can i tag the specific code if i dont know the line where the error accurs, and no effect of the Code you told i remove and change the placement of new item, but no effect

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900