我想要做的是在我的列表視圖中選擇一個項目,它的工作原理!這是它的工作原理,第一次選擇一個項目它很好,第二次得到一個參數超出範圍異常的特徵[0] .SubItems [1] .Text;在零。從列表視圖中選擇項目
這是我有:
private void listViewFeatures_SelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection features = listViewFeatures.SelectedItems;
string feature = features[0].SubItems[1].Text;
BL_AddReport addReport = new BL_AddReport(this.databaseConnectionString);
Dictionary<string, bool> pictures = addReport.GetpicturesFromFeature(feature);
foreach (KeyValuePair<string, bool> pic in pictures)
{
if (pic.Value) {
pictureBoxCar.Image = Image.FromFile(pic.Key);
}
else
{
pictureBoxEquip.Image = Image.FromFile(pic.Key);
}
}
}
有誰知道問題是什麼?
爲什麼不實現一個簡單的'if'聲明,以確保'features.Count> 0'?所有問題都沒有了...... – 2012-03-20 13:08:38
請在您的Page_Load事件處理程序中顯示代碼。這可能是您正在重新加載負載上的數據。 – 2012-03-20 13:09:10
@Alex:你爲什麼認爲這是一個ASP.NET項目?可能是Windows窗體... – 2012-03-20 13:10:00