获取listview列名称时出错

时间:2014-04-08 07:41:12

标签: vb.net

当我使用循环获取列表视图列名称时,我收到错误,如下所示。

这是我的循环:

For xCnt = 2 To lvHolidays.Columns.Count
            strState = lvHolidays.Columns(xCnt).Text
            For Each li In fHoliday.lvStates.Items
                If strState = li.Text Then
                    If lvHolidays.SelectedItems(xCnt).SubItems(xCnt - 1).Text = "Yes" Then
                        li.Checked = True
                    End If
                    Exit For
                End If
            Next
        Next

这是错误:

"InvalidArgument=Value of '18' is not valid for 'index'.
Parameter name: index"

1 个答案:

答案 0 :(得分:0)

试试这个:

For xCnt = 2 To lvHolidays.Columns.Count-1