Jump to content

Problema usando CheckedlistBox en VB 2008


Recommended Posts

Holas soy nuevo trabajando en Visual Basic 2008 y no tengo claro como trabajar con los checkedListBox

se me ha hecho mas complicado dejo mi problema plateado ojala me pudieran ayudar

 

Tengo un CheckListBox con 5 opciones las cuales cada una tiene un precio determinado, el cual en el codigo de abajo.

Entonces al seleccionar una o mas opciones que me sume las que estan marcadas, y me muestre la suma en el label, Creo que eso lo hize bien porque me funciona al seleccionar los item me muestra la suma de los que estan seleccionados, ahora al desmarcar todas las opciones me deja el ultimo valor marcado en el label , y no lo deja en 0 (en tiempo de ejecución)

Como deberia hacerlo para que cuando desmarque la ultima opcion me reste ese valor.

Dejare mi codigo Aki :

 

 

Private Sub chklMotivo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chklMotivo.SelectedIndexChanged

Dim valor As Integer = 0

For i As Integer = 0 To Me.chklMotivo.Items.Count - 1

If Me.chklMotivo.GetItemChecked(i) Then

If i = 0 And Me.chklMotivo.GetItemChecked(i) = True Then

valor += 1000

lblCosto.Text = valor

End If

 

If i = 1 And Me.chklMotivo.GetItemChecked(i) = True Then

valor += 2000

lblCosto.Text = valor

End If

If i = 2 And Me.chklMotivo.GetItemChecked(i) = True Then

valor += 3000

lblCosto.Text = valor

End If

If i = 3 And Me.chklMotivo.GetItemChecked(i) = True Then

valor += 4000

lblCosto.Text = valor

End If

If i = 4 And Me.chklMotivo.GetItemChecked(i) = True Then

valor += 5000

lblCosto.Text = valor

End If

End If

Next i

 

End Sub

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...