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
Solved

Listview help needed

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Optimize the query 5 43
VB.Net. Reading xml value 6 30
Need syntax help building hyperlink 2 27
How to open a different table using the same bindingsource - vb.net 3 36
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

838 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