タイトルが示すように、AfterLabelEdit が起動すると、Return キーを押したり空のスペースをクリックしたりしても、ListViewItem が編集モードでスタックします。
エラー:
タイプ 'System.Collections.Generic.KeyNotFoundException' の初回例外が mscorlib.dll で発生しました
コードは次のようになります。
ListViewItem oldItem;
private void listView_BeforeLabelEdit(object sender, LabelEditEventArgs e)
{
oldItem = listView.Items[e.Item]; // store the unedited item
}
private void listView_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
// make sure the new label has been edited and isn't null
if(e.Label != "" && e.Label != oldItem.Text)
{
// iterate through Dictionary<string, List<string>> dict, find values of the key named oldItem.Text
foreach(var keyValuePair in dict)
{
if(keyValuePair.Key == oldItem.Text)
{
foreach(string s in keyValuePair.Value)
{
if(s != "")
dict[e.Label].Add(s); // ----------------- Error
}
}
}
dict.Remove(oldItem.Text);
}
}
キーと値が null ではないことは確かです。何か案は?まだ不明な点があれば質問してください。