リスト ビューからアイテムを選択しようとしていますが、選択するとそれぞれがテキスト ボックスに表示されます。最初のアイテムを選択して取得することはできますが、2 番目のアイテムを選択するとエラーが発生します。
「範囲外の引数は処理されませんでした。InvalidArgument='0' の値は 'index' には無効です。」
以下のコードがあります。助けてください..
public partial class Form2 : Form
{
List<Person> people = new List<Person>();
}
class Person
{
public string Name{ get; set; }
private void button2_Click(Object sender, EventArgs e)
{
Person p = new Person();
p.Name = textBox1.Text;
people.Add(p);
listBox1.Items.Add(p.Name);
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = people[listView1.SelectedItems[0].Index].Name;
}
}