0

这是我的代码

 int totallikes = 2;
 int currentrep = 0;
 while (currentrep < totallikes)
   {
        string user = accounrLlistview.Items[currentrep].text;
        string pass = accounrLlistview.Items[currentrep].SubItems[1].text;
        //code to do whatever
        currentrep = currentrep + 1;
   }

列表视图由用户在此按钮单击运行之前创建。

我有一个带有用户名密码和 id 的列表视图框,有 2 个集合。
user1 pass1 id1
user2 pass2 id2

我试图让 user2

它第一次工作,但在第二次循环中我得到错误,InvalidArgument = Value of '1' 对于'index' 无效。参数名称:索引

是的,我想写什么

4

1 回答 1

0

使用Items.Count属性来确定您喜欢的项目数:ListView

while (currentrep < accountListview.Items.Count)
{
    string user = accounrLlistview.Items[currentrep].text;
    string pass = accounrLlistview.Items[currentrep].SubItems[1].text;
    //code to do whatever
    currentrep = currentrep + 1;
}

如果它通过第一次遍历,那么index'1' inaccounrLlistview.Items[currentrep].SubItems[1].text不是问题。而最有可能的currentrep是这里的索引Items[]

于 2013-11-04T00:42:28.323 回答