Make sure the selection does not result in an IndexOutOfBoundException.