InvalidArgument ='2'的值对'index'无效

时间:2010-11-04 18:09:54

标签: vb.net combobox indexing

Dim group11_0_count = 0
        Dim group11_1_count = 0
        Dim group11_2_count = 0

        Dim m As Integer = 0
        Dim n As Integer = 0
        Dim increment2 As Integer


        For m = 0 To machings2.Items.Count - 1
            For n = 0 To 3
                If machings2.Items(m).ToString.Chars(n) = "1" Then
                    increment2 = increment2 + 1
                End If
            Next
            If (increment2 = 0) Then
                group11_0_count = group11_0_count + 1
                group11_1_0.Items.Add(machings2.Items(m))
            End If

            If (increment2 = 1) Then
                group11_1_count = group1_1_count + 1
                group11_1_1.Items.Add(machings2.Items(m))
            End If

            If (increment2 = 2) Then
                group11_2_count = group1_2_count + 1
                group11_1_2.Items.Add(machings2.Items(m))
            End If
            increment2 = 0
        Next

        If (group11_0_count > 0 AndAlso group11_1_count > 0) Then
            Dim result = ""
            Dim index As Integer = 0
            Dim gg As Integer = 0
            Dim hh As Integer = 0
            Dim i As Integer = 0
            For hh = 0 To group11_1_count - 1
                For gg = 0 To group11_0_count - 1
                    result = ""
                    index = 0
                    For i = 0 To 3
                        If group11_1_0.Items(gg).ToString.Chars(i) <> group11_1_1.Items(hh).ToString.Chars(i) Then
                            result &= "-"
                            index = index + 1
                        Else
                            result &= group11_1_0.Items(gg).ToString.Chars(i)
                        End If
                    Next

                    If (index = 1) Then
                        machings3.Items.Add(result)
                    End If
                Next
            Next
        End If

我正在比较两个组合框项目的项目

combobox1 items
0000

combobox items
0001
0010

the result will be like that in machings3 combobox
000-
00-0

Here the differnce between two items indicated by - sign

But i am getting InvalidArgument=Value of '2' is not valid for 'index'.

1 个答案:

答案 0 :(得分:0)

我无法理解您的来源以及IndexOutOfRangeException发生的位置。但是你知道你需要一个Combobox中的3个项目来访问索引2的项目吗?!每个集合都以0开头。