如何为3 checkedlistbox中检查的项目执行循环

时间:2015-02-04 08:41:10

标签: vb.net

我做了一份关于公司员工输出的报告。我为此制作了一个代码。但是它只显示了第一个检查的项目。如何在这里进行循环。

   Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    For i = 0 To Employee_Bank_dtl.CheckedListBox1.Items.Count - 1 Step i + 1
        If Employee_Bank_dtl.CheckedListBox1.GetItemCheckState(i) = CheckState.Checked Then
            Dim xx As String = (CType(Employee_Bank_dtl.CheckedListBox1.Items(i), DataRowView))("VC_BRNAME")
            For j = 0 To Employee_Bank_dtl.CheckedListBox2.Items.Count - 1 Step j + 1
                If Employee_Bank_dtl.CheckedListBox2.GetItemCheckState(j) = CheckState.Checked Then
                    Dim yy As String = (CType(Employee_Bank_dtl.CheckedListBox2.Items(j), DataRowView))("vc_empstatus")
                    For k = 0 To Employee_Bank_dtl.CheckedListBox3.Items.Count - 1 Step k + 1
                        If Employee_Bank_dtl.CheckedListBox3.GetItemCheckState(k) = CheckState.Checked Then
                            Dim zz As String = (CType(Employee_Bank_dtl.CheckedListBox3.Items(k), DataRowView))("vc_value")
                            Dim str = "xxxxxxxxxxxxxx"
                            conobj.readdata(str)
                            conobj._adpt.Fill(Me.DataSet10.BRANCH_MAST)
                            Me.ReportViewer1.RefreshReport()
                        End If
                    Next
                End If
            Next
        End If
    Next i

2 个答案:

答案 0 :(得分:0)

你应该通过这样的项目集合来增加,而不是像你那样。您应该能够找到您要查找的属性。在内部循环中设置断点并右键单击项目上的快速计划,您将看到该项目的所有属性,其中包含您要查找的内容。

    For Each item In CheckedListBox1.Items
        'set the item property to the right property that holds "VC_BRNAME"
        If item.property = "VC_BRNAME" Then

        End If
        If item.checkstate.checked = True Then

        End If

    Next

答案 1 :(得分:0)

我在第3次循环中将k + 1替换为+1的错误将得到正确答案