How to obtain the values of the selected items from a CheckBoxList on vb.net?

0

The problem I have is that even though I select a checkbox, it never shows it to me in the Visual Studio debugger, I can get all the values of the items but I only need the selected ones.

I do not want to use JavaScript.

Code VB

For i As Integer = 0 To Roles.Items.Count - 1
    If Roles.Items(i).Selected Then
        MiCargo.pAgregarRolCargo(Roles.Items(i).Value)
    End If
Next

Could you help me? I do not know what happens.

    
asked by Juan Baquedano 19.01.2017 в 03:55
source

2 answers

1

The first thing you have to do is determine which check you have active, and then scroll through to capture the values.

If CheckedListBox1.CheckedItems.Count <> 0 Then
    For i As Integer = 0 To Roles.Items.Count - 1
        If Roles.Items(i).Selected Then
            MiCargo.pAgregarRolCargo(Roles.Items(i).Value)
        End If
    Next
end if
    
answered by 19.02.2017 в 07:57
0

Simple example of going through the listview:

Private Sub BtnAgregar_Click(sender As Object, e As EventArgs) Handles BtnAgregar.Click
        Dim qry As String = ""
        Dim qactualizo As String = ""
        Dim x1 As Date = DateTimePicker3.Value

        Dim fechapago As String
        fechapago = Format(x1, "MM/dd/yyyy")

        For Each item As ListViewItem In LvLista.CheckedItems

            qactualizo = ""
            qactualizo += "  Pagada = True"
            qactualizo += ", Fecha_Pago = '" & fechapago & "'"
            qactualizo += ", Bimestre = '" & CboPeriodo.Text & "'"
            qactualizo += ", Ano = '" & CboAno.Text & "'"

            qry = String.Format("Update facturas set " & qactualizo & " where Id_Factura = " & item.SubItems(0).Text & "")
            EjecutaCmd(qry)
            item.Remove()
        Next
    End Sub
    
answered by 26.05.2017 в 05:01