值"0"对“索引"无效 [英] Value of '0' is not valid for 'index

查看:164
本文介绍了值"0"对“索引"无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

我遇到了一个问题,正在寻求帮助.

I've run into a bit of a problem and am looking for help.

我有数据转到主窗体上的另一个列表视图.无论如何,我有一个WinXP机器上的用户告诉我以下错误:

I have data that goes to another listview on the main form. Anyways, I have a user on a WinXP machine tell me about the following error:

System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'index'.

所以主要问题是'0'的值对于'索引'无效."当提交"单击按钮,将数据发送到主窗体上的列表视图.

So the main problem is "Value of '0' is not valid for 'index'." when the "Submit" button is clicked, sending this data to the listview on the main form.

这是负责此操作的代码部分:

Here is the section of code responsible for this:

        Select Case x.bAllowEntryEditing
            Case False '// if normal entry add.
                '// configure the text for lvMain # column.
                Dim number As String = frmMain.lvMain.Items.Count
                If number = 0 Then : number = 1 : Else : number += 1 : End If '// if no entries, set # to 1, else add +1 to #.
                If number < 10 Then : number = "00" & number : ElseIf number < 100 Then : number = "0" & number : End If '// format to ###.

                Dim newItem As New ListViewItem(number) '// declare a new ListView item.
                With newItem.SubItems
                    '// add Start/End Time.
                    .Add(txtStart.Text) : .Add(txtEnd.Text)
                    '// add Total Time.
                    If Not txtTotalTime.Text = "0000" Then : .Add(txtTotalTime.Text)
                    Else : .Add("0001")
                    End If
                    '// add Location and Call Type.
                    If Not lvCallTypes.SelectedItems.Count = 0 Then '// check if Call Types has a selection.
                        .Add(lvAreaLocations.SelectedItems(0).Text & " ~ " & lvCallTypes.SelectedItems(0).Text)
                    Else : If Not lvAreaLocations.SelectedItems.Count = 0 Then '// check if Location has a selection.
                            .Add(lvAreaLocations.SelectedItems(0).Text & " ~ ") '// only add Location.
                        Else : .Add("") '// add empty value if No Location Or Call Type selected.
                        End If
                    End If
                    '// add Notes and Case number.
                    .Add(txtCallNotes.Text) : .Add(txtCase.Text)

推荐答案

我能够进一步研究-这行代码引发了错误-

I was able to look into this further- this line of code is throwing the error-

.SubItems(4).Text = lvAreaLocations.SelectedItems(0).Text & " ~ " & lvCallTypes.SelectedItems(0).Text


这篇关于值"0"对“索引"无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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