如何获取checkedlistbox中选中的项目
How to get the checked items in checklistbox
我有一个清单框,其中的项目来自我的数据库 (tbl_Section),所以它加载了所有的节号(主键)。我有 5 个 Section Numbers,其中 3 个只会分配给一位老师。我正在考虑使用 While 语句,但我不知道如何使用。
为了让你更简单,这是我需要做的:
While //index(number) is checked
//do something
Else (i know it should not be ELSE, but i dont know what keyword is to be used)
//do something
End While
非常感谢!
您要做的是遍历复选框中的每个项目。对于每一项,你检查它是否被选中,然后你相应地采取行动:
'We will run through each indice
For i = 0 To CheckedListBox1.Items.Count - 1
'You can replace As Object by your object type
'ex : Dim Item As String = CType(CheckedListBox1.Items(i), String)
Dim Item As Object = CheckedListBox1.Items(i)
'We ask if this item is checked or not
If CheckedListBox1.GetItemChecked(i) Then
'Do something if Item is checked
Else
'Do something else if Item is not checked
End If
Next
我有一个清单框,其中的项目来自我的数据库 (tbl_Section),所以它加载了所有的节号(主键)。我有 5 个 Section Numbers,其中 3 个只会分配给一位老师。我正在考虑使用 While 语句,但我不知道如何使用。
为了让你更简单,这是我需要做的:
While //index(number) is checked
//do something
Else (i know it should not be ELSE, but i dont know what keyword is to be used)
//do something
End While
非常感谢!
您要做的是遍历复选框中的每个项目。对于每一项,你检查它是否被选中,然后你相应地采取行动:
'We will run through each indice
For i = 0 To CheckedListBox1.Items.Count - 1
'You can replace As Object by your object type
'ex : Dim Item As String = CType(CheckedListBox1.Items(i), String)
Dim Item As Object = CheckedListBox1.Items(i)
'We ask if this item is checked or not
If CheckedListBox1.GetItemChecked(i) Then
'Do something if Item is checked
Else
'Do something else if Item is not checked
End If
Next