经过几个小时的尝试,我能够得到一个绑定到 SQL 源的检查列表。但是,现在我想检索检查列表中已检查的所有项目。我尝试了上面的代码,但它不起作用
For i As Integer = 0 To checkList_Facility.Items.Count - 1
If (checkList_Facility.GetItemChecked(i)) = True Then
MsgBox(checkList_Facility.Items(i))
End If
Next
绑定代码:
Dim queryString As String = "SELECT Facility FROM Database.dbo.Facility"
Dim connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(queryString, connection)
connection.Open()
Dim dataReader As SqlDataReader = command.ExecuteReader()
Dim var As New DataTable
Dim source As New BindingSource
source.DataSource = dataReader
CheckList_Facility.DataSource = source
CheckList_Facility.ValueMember = "Facility"
connection.Close()