Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

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

0
peter-cooper
Asked:
peter-cooper
  • 2
  • 2
1 Solution
 
piattndCommented:
In your debug, do you see the listViewItem as having 4 subitems or 5?
0
 
peter-cooperAuthor Commented:
Hi. It is 5. thanks
0
 
piattndCommented:
Can you post the exact error this code is giving you?  Also, paste in the line that the error directly references.
0
 
peter-cooperAuthor Commented:
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now