Hi,
 
I have a list view that pulls records from a Database, and that works.
 
I want to select a row and pass the record Name, Number and Date to three Text Boxes.
 
With the code I have, I can do that just fine, but just once.  I select the customer from a listbox, then it displays that customer's records in a seperate listview.  
 
If there are no records, there is no problem.
If there is one record, there is no problem.
If there is more than one record, I can click on any record in the list, and it passes the Name, Number and Date to my textboxes, which is what I want.
 
But, here is the problem, if I select a second record then it throws this error:
 
System.ArgumentOutOfRangeException: 'InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index'
 
 
This is my code which retrieves the records from my database and populates listView1 (this works just fine):
- try  
- {  
- conDataBase3.Open();  
- myReader = cmdDataBase.ExecuteReader();  
- while (myReader.Read())  
- {  
- ListViewItem item = new ListViewItem(myReader["RUAName"].ToString());  
- item.SubItems.Add(myReader["RUANumber"].ToString());  
- item.SubItems.Add(myReader["RUAExpiryDate"].ToString());  
- listView1.Items.Add(item);  
- }   
 
Now this is the code that works just fine once, but crashes with the above error if I select a second record:
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)  
- {  
- string lvname = listView1.SelectedItems[0].SubItems[0].Text;  
- string lvnumber = listView1.SelectedItems[0].SubItems[1].Text;  
- string lvdate = listView1.SelectedItems[0].SubItems[2].Text;  
- textBox2.Text = lvname;  
- textBox1.Text = lvnumber;  
- dateTimePicker1.Text = lvdate;  
- }   
Any suggestions would be appreciated, 
 
Thank you!
G