VB.NET获取ListBox中的所有项目并传递给参数

时间:2013-09-29 11:49:27

标签: vb.net listbox parameter-passing

您好我的循环将我的列表框中的所有项目传递给水晶报表参数。

    For i = 0 To ListBoxBillAccount.Items.Count - 1
        If ListBoxBillAccount.Items(i).selected Then
            crParameterDiscreteValue = New ParameterDiscreteValue()
            crParameterDiscreteValue.Value = ListBoxBillAccount.SelectedItems()
            crParameterValues.Add(crParameterDiscreteValue)
        End If
    Next

我收到了错误消息:"公共成员'已选中'在类型' DataRowView'没找到。"

编辑:这是我的完整代码:

   Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldDefinition As ParameterFieldDefinition
    Dim crParameterValues As New ParameterValues
    Dim crParameterDiscreteValue As New ParameterDiscreteValue
    crParameterFieldDefinitions = crReportDoc.DataDefinition.ParameterFields
    crParameterFieldDefinition = crParameterFieldDefinitions("UserAcct")
    crParameterValues = crParameterFieldDefinition.CurrentValues

    For i = 0 To ListBoxBillAccount.Items.Count - 1
        If ListBoxBillAccount.Items(i).selected Then
            crParameterDiscreteValue = New ParameterDiscreteValue()
            crParameterDiscreteValue.Value = ListBoxBillAccount.SelectedItems()
            crParameterValues.Add(crParameterDiscreteValue)
        End If
    Next

    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    frmGenerateConsolidatedBill.CrystalReportViewer1.ReportSource = crReportDoc
    frmGenerateConsolidatedBill.Refresh()
    frmGenerateConsolidatedBill.Show()

1 个答案:

答案 0 :(得分:0)

也许:

For Each obj In ListBoxBillAccount.SelectedItems()
    Dim crParameterDiscreteValue = New ParameterDiscreteValue()
    crParameterDiscreteValue.Value = obj
    crParameterValues.Add(crParameterDiscreteValue)
Next