索引结束时如何重新启动索引选择 [英] How can I restart my index selection once index has reached the end

查看:243
本文介绍了索引结束时如何重新启动索引选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到达终点后,我正尝试循环回到列表视图项的开头.相反,我不断收到"System.ArgumentOutOfRangeException:" InvalidArgument ="21"的值对"index"无效."错误.

这是我的代码:

I am trying to loop back to the beginning of my listview items once I have reached the end. Instead, I keep getting a "System.ArgumentOutOfRangeException: ''InvalidArgument=Value of ''21'' is not valid for ''index''." error.

here is my code:

Dim previousSelectedIndex As Integer = Me.SelectedItems(0).Index

               If Me.SelectedIndices(0) < 21 Then
                   Me.Items(previousSelectedIndex + 1).Selected = True
               Else

                   Me.Items(previousSelectedIndex).Selected = False
                   Me.Items(0).Selected = True
               End If



我尝试过的事情:

我已经尝试过声明.但是,我也尝试使用elseif也不起作用.



What I have tried:

I have tried to flip the statement. I also tried to use an elseif, however, that didn''t work either.

推荐答案

解决了我的问题.现在我的选择过程从顶部开始,到结束时,我可以按Enter键,它将带我回到顶部.

这是代码:

Fixed my problem. now my selection process starts at the top and when it reaches the end I can press enter and it will bring me back to the top.

Here is the code:

Dim previousSelectedIndex As Integer = Me.SelectedItems(0).Index

               If Me.Items.Item(previousSelectedIndex).Index = Me.Items.Count - 1 Then
                   Me.Items(0).Selected = True
               Else
                   Me.Items(previousSelectedIndex + 1).Selected = True
               End If


为什么对您的值进行硬编码?如果这是一个循环,则可以检查该值是否已到达序列末尾并将其重置为零.为什么要无限循环?
Why is your value hard coded? If this is a loop, you can check if the value has reached the end of your sequence and reset it to zero. Why do you want to loop endlessly?


这篇关于索引结束时如何重新启动索引选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆