我有一个我正在开发的小型 C# 3.5 WinForms 应用程序,它将事件日志名称从服务器抓取到列表视图中。When one of those items is selected, another listview is populated with the event log entries from the selected event log using the SelectedIndexChanged event by grabbing the text property of the 1st item in the SelectedItems collection as shown below.
string logToGet = listView1.SelectedItems[0].Text;
这第一次工作正常,但从第一个列表视图中第二次选择事件日志名称失败。发生的事情是 SelectedIndexChanged 事件正在获取的 SelectedItems 集合为空,因此我得到了 ArgumentOutOfRangeException。
我很茫然。关于我做错了什么或更好的方法的任何想法?