Solved

Listview help needed

Posted on 2013-12-12
4
180 Views
Last Modified: 2014-01-04
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
Comment
Question by:peter-cooper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
piattnd earned 500 total points
ID: 39714297
In your debug, do you see the listViewItem as having 4 subitems or 5?
0
 

Author Comment

by:peter-cooper
ID: 39719816
Hi. It is 5. thanks
0
 
LVL 12

Expert Comment

by:piattnd
ID: 39721746
Can you post the exact error this code is giving you?  Also, paste in the line that the error directly references.
0
 

Author Closing Comment

by:peter-cooper
ID: 39756553
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question