Note that there are some explanatory texts on larger screens.

plurals
  1. POYouTube Tutorial Can't select second Item in Listview (Invalid argument)
    primarykey
    data
    text
    <p>I am trying to follow along and complete this address book tutorial on YouTube <a href="http://www.youtube.com/watch?v=0ZoDmeAZAD8&amp;feature=relmfu" rel="nofollow">Address Book Tutorial</a></p> <p>But I have ran into a snag that I don't understand. Following along I cannot find the difference in code. So I am thinking it must be a property setting that I am missing. When I test populate the list I can select the first item. But when I select the second item the debugger kicks out an error </p> <blockquote> <p>invalid argument=value of '0' is not valid for 'index'</p> </blockquote> <p>Can someone tell me why this error is thrown? Listening to the video it sounds like the 0 in the code is to tell the list that you can only select one item at a time. Unfortunately I haven't been able to figure out why his code works and mine does not. </p> <pre><code>private void button3_Click(object sender, EventArgs e) { person p = new person(); // creates new string array p.Name = textBox1.Text; // name p.StreetAddress= textBox3.Text; // address p.Email = textBox2.Text; // email p.Birthday = dateTimePicker1.Value; //birthday p.AdditionalNotes = textBox4.Text; // any notes people.Add(p); // tells the the above data to be added to the people list. listView1.Items.Add(p.Name); // makes its show on the listview of the main box. textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; dateTimePicker1.Value = DateTime.Now; } private void listView1_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = people[listView1.SelectedItems[0].Index].Name; //Debugger points error here. textBox2.Text = people[listView1.SelectedItems[0].Index].Email; textBox3.Text = people[listView1.SelectedItems[0].Index].StreetAddress; textBox4.Text = people[listView1.SelectedItems[0].Index].AdditionalNotes; dateTimePicker1.Value = people[listView1.SelectedItems[0].Index].Birthday; } class person { public string Name { get; set; } ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload