Link to home
Start Free TrialLog in
Avatar of peter-cooper
peter-cooper

asked on

Listview help needed

I am confused being a relatively new user to vb.net. Why my listview is not amending the value in the list? If I may, so I have a correct working of how listview displays its data from database. I have a general question in addition to my code problem.

I have five columns in my listview (0-4). Am I correct in saying that if my access database contained say 10 fields but I only needed to display five of them but one of them was field (9), then would code the list like my code below, which is not changing the value and will only display the list if I remove the 'else' statement.

The statement that festures subitems(3), is working fine, so what is the difference.

What is the error? Many thanks


Using dr = oledbCmd.ExecuteReader()


                'clear items in the list before populating with new values
                'lvRequests.Items.Clear()

                While dr.Read()
                    If dr.HasRows Then

                        lvRequests.Items.Add((dr(0)).ToString()).UseItemStyleForSubItems = False
                        lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(CDate(dr(5)).ToShortDateString())
                        lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(1).ToString())

                        With lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(3).ToString())

                            If dr(3).ToString() = "D" Then
                                lvRequests.Items(lvRequests.Items.Count - 1).SubItems(3).Text = "Destroyed"

                            ElseIf dr(3).ToString = "O" Then
                                lvRequests.Items(lvRequests.Items.Count - 1).SubItems(3).Text = "Out"

                            ElseIf dr(3).ToString = "I" Then
                                lvRequests.Items(lvRequests.Items.Count - 1).SubItems(3).Text = "Intake"

                            End If

                        End With


                        With lvRequests.Items(lvRequests.Items.Count - 1).SubItems.Add(dr(9).ToString())

                            If dr(9).ToString() = "DEMO" Then
                                lvRequests.Items(lvRequests.Items.Count - 1).SubItems(9).Text = "Done"
                                'Else
                                '    '    dr(9).ToString()
                                'lvRequests.Items(lvRequests.Items.Count - 1).SubItems(9).Text = "Nothing"

                            End If


                        End With

                        lvcount += 1

                    End If

                End While
            End Using

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of piattnd
piattnd

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
Avatar of peter-cooper
peter-cooper

ASKER

Hi. It is 5. thanks
Can you post the exact error this code is giving you?  Also, paste in the line that the error directly references.
Thanks