Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB VB10.0 VB.NET
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 7-Apr-13 23:09pm
Edited 8-Apr-13 6:48am
CPallini328.8K
v2
Comments
CHill60 at 8-Apr-13 8:56am
   
What IS the problem - you haven't asked a question yet
CPallini at 8-Apr-13 11:50am
   
Could you please elaborate the observed problem of you code?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
listview1.items.add(newitem)
should not be inside the With statement.
 
You're also calling
ListView1.Items.Clear()
ListView1.Columns.Clear()
twice.
  Permalink  
Comments
Zubair Lohani at 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)

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 165
2 PIEBALDconsult 150
3 BillWoodruff 148
4 DamithSL 140
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100