Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ListView not loading properly

Hi

I am using the following code to load a ListView.
Only the first record "Number" seems to be loading correctly
 User generated image
even though my data looks as follows

Sub Fill_Rooms_ListView()
        Try
            Me.ListView_Rooms.Items.Clear()
            Me.ListView_Rooms.BeginUpdate()
            Using myConnection As New OleDbConnection(ConnectionString)
                Dim myCommand As New OleDbCommand("SELECT * FROM [Rooms]", myConnection)
                myConnection.Open()
                Using dr As OleDbDataReader = myCommand.ExecuteReader
                    Do While dr.Read
                        Dim myItem As ListViewItem = Me.ListView_Rooms.Items.Add(dr("Number").ToString())
                        myItem.SubItems.Add(dr("Rate Single").ToString())
                        myItem.SubItems.Add(dr("Rate Double").ToString())
                        myItem.SubItems.Add(dr("Description").ToString())
                    Loop
                End Using
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Me.ListView_Rooms.EndUpdate()
        End Try
    End Sub

Open in new window

image2.jpg
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Hello, set the View property of your ListView to Details, example:
Me.ListView_Rooms.View = System.Windows.Forms.View.Details

Open in new window

From the designer, example:
 User generated image
Avatar of Murray Brown

ASKER

That still doesn't work.
I get  the following

        User generated image
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You will need 4 columns instead of 3
thanks very much
Glad to help