简体   繁体   English

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

[英]My checklistbox doesn't display my array in VB

I'm writing a program to be used by my library as a step by step checklist when adding new materials (books) to the collection. 我正在编写一个程序,供我的图书馆在向收藏夹中添加新材料(书)时用作逐步检查清单。

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

I expect to have the array displayed in the CLB upon execution 我希望在执行时将数组显示在CLB中

Try looping through your array and add each item into it. 尝试遍历数组并将每个项目添加到其中。

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

Your script will not execute the correct way because your using selected index changed but this will only run when a item has been selected in the list. 您的脚本将无法以正确的方式执行,因为您使用的所选索引已更改,但是只有在列表中选择了某个项目后,脚本才会运行。

The best way to test this is by creating a new button and assigning this code to that button. 最好的测试方法是创建一个新按钮并将此代码分配给该按钮。 With the button, the script will execute on click. 使用按钮,脚本将在单击时执行。

Public sub btnAccept (sender as object, e and eventargs) handles btnAccept.click 公共子btnAccept(作为对象的发送者,e和eventargs)处理btnAccept.click

Dim strProperPackage() As String = {"Call Number and Authors Last name?", "Sub-Category Sticker?", "Plastic Wrapping on the Cover if needed?"} Dim strProperPackage()As String = {“电话号码和作者的姓氏?”,“子类别标签?”,“是否需要在封面上进行塑料包装?”}

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

End Sub 结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM