简体   繁体   English

仅在复选框中选中的项目填充combox

[英]Populate combox with only items that get checked in a checklistbox

I want the checked items in the checklistbox to only populate the combobox. 我希望复选框中的已选中项目仅填充组合框。

    For i As Integer = 0 To chekBoxList1.Items.Count - 1
        If chekBoxList1.GetItemCheckState(i) = CheckState.Checked Then
            comboBox1.Items(i).Add = chekBoxList1.Items(i)
        End If
    Next

This code gets highlighted for an error: cboShipment.Items(i).Add = chkLstShipments.Items(i) 这段代码因错误而突出显示: cboShipment.Items(i).Add = chkLstShipments.Items(i)

The Error: 错误:

"InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index" “ InvalidArgument =值'0'对于'索引'无效。参数名称:索引”

Any suggestion for correction is appreciated! 任何纠正建议,不胜感激!

使用ComboBox1.Items.Add(chekBoxList1.Items(i))

While others in the comments suggested the second problem, you do not need to specify an index when using .Add(). 尽管注释中的其他问题建议了第二个问题,但使用.Add()时无需指定索引。

To fix this completely, the final line should look like such: 要完全解决此问题,最后一行应如下所示:

comboBox1.Items.Add(chekBoxList1.Items(i))

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

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