ArgumentOutOfRangeException for ListViewItem when clicking 2nd time

余生长醉 提交于 2019-12-02 09:30:55

You are getting an error because your first if statement will never evalute to true (and return) since count will never go below 0. Due to this, even if your list is empty it still tries to delete the first element, throwing an ArgumentOutOfRangeException.

Your if statement should instead check if it is equal to 0, as such:

 if (li.SelectedItems.Count == 0)

Nothing happens when you press anything except Alt/Control because you are not handling the event for any key press other than those,

 Control.ModifierKeys == Keys.None

Means that no keys are pressed as opposed to anything except Alt/Control being pressed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!