我的清单框未在VB中显示我的阵列

时间:2019-07-12 14:50:31

标签: arrays vb.net checklistbox

我正在编写一个程序,供我的图书馆在向馆藏中添加新材料(书)时用作逐步检查清单。

Option Explicit On
Option Strict On

Public Class frmCircCounter

    Public ReadOnly Property Items As CheckedListBox.ObjectCollection

    'confirms all boxes have been checked, and clears them
    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

        'If

        '    End If

    End Sub

    Private Sub CheckedListBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox4.SelectedIndexChanged

        'I'm not sure what this is for the internet told me to add this?
        InitializeComponent()

        'establishes the arrary displayed in the checklistbox
        Dim strProperPackage() As String = {"Call Number and Authors Last name?", "Sub-Category Sticker?", "Plastic Wrapping on the Cover if needed?"}

        'displays it... or it should!!!?
        clbProperPackage.Items.AddRange(strProperPackage)

    End Sub

End Class

我希望执行后将数组显示在CLB中

2 个答案:

答案 0 :(得分:0)

尝试遍历数组并将每个项目添加到其中。

For Each item As String In strProperPackage
  clbProperPackage.Items.Add(item)
Next

答案 1 :(得分:0)

您的脚本将无法执行正确的方式,因为您使用的所选索引已更改,但是只有在列表中选择了一项后,该脚本才会运行。

最好的测试方法是创建一个新按钮并将此代码分配给该按钮。使用该按钮,脚本将在单击时执行。

公共子btnAccept(作为对象,e和eventargs发送者)处理btnAccept.click

将strProperPackage()设置为String = {“电话号码和作者的姓氏?”,“子类别标签?”,“是否需要在封面上进行塑料包装?”}

'显示它...还是应该!!? clbProperPackage.Items.AddRange(strProperPackage)

结束子