Solved

Listview help needed

Posted on 2013-12-12
4
176 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now