Public Sub FillChkListBox(ByVal lb As CheckedListBox, ByVal sql As String, ByVal ParameterName As String, ByVal ParameterValue As String)
Dim connetionString As String
Dim connection As SqlConnection
Dim command As SqlCommand
Dim dt As DataTable
Dim adapter As New SqlDataAdapter
' Dim ds As New DataSet
Dim i As Int32
connetionString = myCN
connection = New SqlConnection(connetionString)
Try
connection.Open()
command = New SqlCommand(sql, connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue(ParameterName.ToString, ParameterValue.ToString)
dt = New DataTable
dt.Load(command.ExecuteReader)
adapter.Dispose()
command.Dispose()
connection.Close()
lb.DataSource = dt
lb.DisplayMember = dt.Columns(1).ColumnName
lb.ValueMember = dt.Columns(0).ColumnName
Catch ex As Exception
End Try
End Sub
Private Sub lblAddToList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblAddToList.Click
For Each x In Me.chkBoxAvailable.CheckedIndices
'' I want to capture the value not the text of each checked item
MsgBox(Me.chkBoxAvailable.Text.ToString)
MsgBox(Me.chkBoxAvailable.SelectedValue.ToString)
Next
End Sub
|