?
Solved

Don get value from my listview

Posted on 2007-11-23
3
Medium Priority
?
409 Views
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.GetInt32(1))
                lstItem.SubItems.Add(dataleser.GetInt32(2))
                lstItem.SubItems.Add(dataleser.GetOracleDateTime(3))
                'lstItem.SubItems.Add(dataleser.GetInt32(4))
                lstItem.SubItems.Add(dataleser.GetString(5))
                'lstItem.SubItems.Add(dataleser.GetString(6))
                lstItem.SubItems.Add(dataleser.GetInt32(7))
                lstItem.SubItems.Add(dataleser.GetString(8) & " " & dataleser.GetString(9))
                lstItem.SubItems.Add(dataleser.GetString(10) & " " & dataleser.GetString(11) & " " & dataleser.GetString(12))
                'lstItem.SubItems.Add(dataleser.GetString(11))
                'lstItem.SubItems.Add(dataleser.GetString(12))
                lstItem.SubItems.Add(dataleser.GetInt32(13))
                'lstItem.SubItems.Add(dataleser.GetString(14))
 
                Me.listviewordre.Items.Add(lstItem)
 
 
            End While

Open in new window

0
Comment
Question by:leeds2000
[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
3 Comments
 
LVL 3

Author Comment

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

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

Accepted Solution

by:
Jaime Olivares earned 2000 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



0
 
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 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