开发者

Setting does not get removed?

I have both a ListBox (AlarmBox) and a ListView (listView1). They both save into 2 different Properties.Settings (AlarmList and AlarmList2).

Properties.Settings.Default.AlarmList.Remove(AlarmList.SelectedItem);
Properties.Settings.Default.AlarmList2.Remove(listView1.SelectedItems);
AlarmList.Items.RemoveAt(AlarmList.SelectedIndices[0]);
listView1.Items.RemoveAt(listView1.SelectedIndices[0]);

That's th开发者_如何学运维e code for the remove button, but since listView1 doesn't have a SelectedItem function, I resorted to using SelectedItems.

When removing an item from both boxes, AlarmBox removes the values correctly from both the application and the settings, but when removing from listView1, the value is only removed from the app, but isn't removed from the settings.

EDIT: Also, when replacing listView1.SelectedItems with AlarmList.SelectedItem, it removes correctly.


Have you tried

.Remove(listView1.SelectedItems[0]);

OK, then how about trying the RemoveAt with the index?

.RemoveAt(listView1.SelectedItems[0].Index);


You don't refer to AlarmBox at all in the sample code, only to AlarmList.
Is it correct to be referencing listView1, or should you be referring to AlarmList2 instead?

At a glance, it looks a bit mixed up...

Glad it's solved! I should have refreshed before posting!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜