主题:关于ListView中列表项选择的错误问题
我想实现一个功能,选中ListView中一行,可取出改行的text。我将这功能写在SelectedIndexChanged事件中
private void MyListView_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(this.MyListView.SelectedItems[0].Text);
}
可是当我第一次单击某行的时候,正确。但我第二次单击任何行的时候却报错了。
错误提示为:
An unhandled exception of type 'system.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll
Additional information: InvalidArgument=“0”的值对于“index”无效
同样的语句,我使用
private void MyListView_Click(object sender, EventArgs e)
{
MessageBox.Show(this.MyListView.SelectedItems[0].Text);
}
这个事件函数,一切正常。
谁能告诉我,这是为什么?
private void MyListView_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show(this.MyListView.SelectedItems[0].Text);
}
可是当我第一次单击某行的时候,正确。但我第二次单击任何行的时候却报错了。
错误提示为:
An unhandled exception of type 'system.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll
Additional information: InvalidArgument=“0”的值对于“index”无效
同样的语句,我使用
private void MyListView_Click(object sender, EventArgs e)
{
MessageBox.Show(this.MyListView.SelectedItems[0].Text);
}
这个事件函数,一切正常。
谁能告诉我,这是为什么?