Don get value from my listview

Posted on 2007-11-23
Last Modified: 2008-02-07
here is the code im using to drag the value from the listview

        Dim vareantall As String = Me.listviewordre.SelectedItems.(2).Text
        Dim varenummer As String = Me.listviewordre.SelectedItems(1).Text

Below is the code for my listview, why dont i get the values i need??

And yes i have values inside my listview box, they are gathered from a database, but i get error when trying the code above, to get values from column 1 and 2
With Me.listviewordre

                .GridLines = True

                .MultiSelect = False

                .FullRowSelect = True

                .View = View.Details

                .HideSelection = False

                .Columns.Add("O. nr", 35, HorizontalAlignment.Center)

                .Columns.Add("V. nr", 35, HorizontalAlignment.Center)

                .Columns.Add("Ant.", 35, HorizontalAlignment.Center)

                .Columns.Add("Salgsdato", 68, HorizontalAlignment.Center)

                '.Columns.Add("Kundenr", 45, HorizontalAlignment.Center)

                .Columns.Add("Varenavn", 111, HorizontalAlignment.Center)

                '.Columns.Add("Varetype", 65, HorizontalAlignment.Center)

                .Columns.Add("Pris", 50, HorizontalAlignment.Center)

                .Columns.Add("Kundenavn", 100, HorizontalAlignment.Center)

                .Columns.Add("Adresse", 185, HorizontalAlignment.Center)

                '.Columns.Add("Postnummer", 65, HorizontalAlignment.Center)

                '.Columns.Add("Poststed", 65, HorizontalAlignment.Center)

                .Columns.Add("Ansatt", 45, HorizontalAlignment.Center)

                '.Columns.Add("Fullført", 55, HorizontalAlignment.Center)

            End With

            Dim lstItem As ListViewItem

            While dataleser.Read()

                lstItem = New ListViewItem()

                lstItem.Text = dataleser.GetInt32(0)








                lstItem.SubItems.Add(dataleser.GetString(8) & " " & dataleser.GetString(9))

                lstItem.SubItems.Add(dataleser.GetString(10) & " " & dataleser.GetString(11) & " " & dataleser.GetString(12))






            End While

Open in new window

Question by:leeds2000
  • 2

Author Comment

ID: 20338500
I do get values from .selecteditems(0)

is this becouse the others are subitems? how do i get values from subitems?
LVL 55

Accepted Solution

Jaime Olivares earned 500 total points
ID: 20338506
>>but i get error when trying the code above, to get values from column 1 and 2
First question: do you really have the items (rows) selected? If not, this will produce an exception:
Dim vareantall As String = Me.listviewordre.SelectedItems.(2).Text
Dim varenummer As String = Me.listviewordre.SelectedItems(1).Text

I think you are confused on how to get the column 1 and 2 (first and second). By example, to get the 1st and 2nd column of the first item in the listview, should be:

Dim vareantall As String = Me.listviewordre.Items.(0).SubItems(0).Text
Dim varenummer As String = Me.listviewordre.Items(0).SubItems(1).Text

LVL 55

Expert Comment

by:Jaime Olivares
ID: 20338511
SelectedItems returns the list of items that are currently selected, that is, highlighted (just one if MultiSelect is set to False).
But if there is not selected item or there are less items selected than what you are trying to access, then you will cause an Exception.

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

19 Experts available now in Live!

Get 1:1 Help Now