Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

error when trying to get information out of listview box

Posted on 2007-11-22
5
Medium Priority
?
175 Views
Last Modified: 2010-04-23
First part of the code is where i get my error:

Argument out of range exception was unhandled - Invalid argument value=0 is invalid for a index

This is very weird, since i have used the same code several other places without no problem.

Il post the code for the listview. (i have values in this listview too, so there should be values to get out)
private sub button click
 
Me.listviewordre.Clear()
        Dim ordrenr As String = Me.listviewordre.SelectedItems(0).Text  <------- ERROR LINE
        MsgBox(ordrenr)
        Exit Sub
 
 
        Me.kjorInsert("DELETE Ordreinfo WHERE ordre_nr = " & ordrenr)
 
        Me.kjorInsert("DELETE Ordre WHERE ordre_nr = " & ordrenr)
 
        Call Me.Oppdaterlistviewordre()
 
end sub
 
 
------------------------------------------------------------------------------------------
 
 
Listview code:
 
Me.listviewordre.Clear()
        Dim forbindelse1 As New System.Data.OracleClient.OracleConnection
 
        forbindelse1.ConnectionString = "user id=****;password=***;data source=***"
        forbindelse1.Open()
 
        Dim kommando As New System.Data.OracleClient.OracleCommand("SELECT o.ordre_nr, oi.vare_nr, oi.vare_antall, oi.salgs_dato, oi.knd_nr, v.vare_navn, v.vare_type, v.vare_pris, k.knd_fornavn, k.knd_etternavn, k.knd_adresse, k.post_nr, s.poststed, oi.ans_nr, o.fullført FROM Ordre o, Ordreinfo oi, Vare v, Kunde k, Sted s WHERE oi.ordre_nr = o.ordre_nr AND oi.vare_nr = v.vare_nr AND k.knd_nr = oi.knd_nr AND s.post_nr = k.post_nr AND o.fullført = 'nei'", forbindelse1)
        Dim dataleser As OracleClient.OracleDataReader
        dataleser = kommando.ExecuteReader()
 
        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
 
        dataleser.Close()
        forbindelse1.Close()

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
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 20336290
When you call
Me.listviewordre.Clear()

You are clearing the listview, so there are no items to select.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20336305
I guess you need something like this:
 
if Me.listviewordre.SelectedItems.Count > 0 Then
        Dim ordrenr As String = Me.listviewordre.SelectedItems(0).Text  <------- ERROR LINE
        MsgBox(ordrenr)
else
        MsgBox("List is empty")
end if

Me.listviewordre.Clear()
 
 
 
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20336323
i have the same code on another listview, there it works perfectly, the clear listview is after the selected item, and i DO select a value then press the button, this would make it have a value before the clear listview right?

Il try and insert the IF sentence, but i dont think it would solve my problem.

I know it has values before the listview gets cleared, i just dont understand :/
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20336342
OHHHHHHHHHHHHHH

yes i see now, i have a listview.clear on top of my button!! this was not suppose to be there :D

THANKS :)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20336470
Hey, I've had days like that too.  :)  Glad you got it working.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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