Foros del Web » Programación para mayores de 30 ;) » .NET »

Como eliminar el registro de un listbox?

Estas en el tema de Como eliminar el registro de un listbox? en el foro de .NET en Foros del Web. Ola,bueno soy nuevo en lo que es programacion y por eso recuro a su ayuda...tengo un formulario en la cual ingreso datos y al presionar ...
  #1 (permalink)  
Antiguo 09/05/2012, 13:35
JHD
 
Fecha de Ingreso: marzo-2011
Mensajes: 1
Antigüedad: 13 años, 1 mes
Puntos: 0
Exclamación Como eliminar el registro de un listbox?

Ola,bueno soy nuevo en lo que es programacion y por eso recuro a su ayuda...tengo un formulario en la cual ingreso datos y al presionar el boton guardar,se guardan los datos...y hay un boton "listar" donde me muestra lo guardado en un listbox,y puse un boton "eliminar" se que es con el RemoveAt, me eliminar lo seleccionado en el listbox,pero al volver a presionar el boton"Listar" aparece de nuevo,como hago para que no vuelva a salir? ai les dejo los codigos...espero me puedan ayudar y de ante mano Gracias..



Public Class Form2
Dim xcodigo(0 To 19) As String
Dim xnombre(0 To 19) As String
Dim xdireccion(0 To 19) As String
Dim xcredito(0 To 19) As Double
Dim xdistrito(0 To 19) As String
Dim n As Short
Dim f As Short = -1

Private Sub btnnuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnuevo.Click
Static c As Short
c = c + 1
txtcodigo.Text = "c" + Strings.Right("00" + Trim(CStr(c)), 3)
txtnombre.Clear()
txtdireccion.Clear()
txtcredito.Clear()
cbodistrito.Text = ""
txtnombre.Focus()
btnnuevo.Enabled = False
btnguardar.Enabled = True


End Sub


Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnguardar.Enabled = False
cbodistrito.Items.Add("lince")
cbodistrito.Items.Add("breña")
cbodistrito.Items.Add("los olivos")
cbodistrito.Items.Add("san migel")
cbodistrito.Items.Add("miraflores")

With cbodis.Items
.Add("Lince")
.Add("breña")
.Add("los olivos")
.Add("san miguel")
.Add("miraflores")
End With

End Sub


Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnguardar.Click
If txtcodigo.Text = "" Then
MsgBox("presione boton nuevo", 32, "aviso")
btnnuevo.Focus()
Exit Sub
End If
If txtnombre.Text.Trim = "" Then
MsgBox("ingrese nombre", 32, "aviso")
txtnombre.Focus()
Exit Sub
End If
If Not IsNumeric(txtcredito.Text) Then
MsgBox("ingrese credito ,solo numero", 32, "aviso")
txtcredito.Focus()
Exit Sub
End If
If MsgBox("desea guardar los datos", 32 + 4, "aviso") = 6 Then
f = f + 1
If f < 20 Then
xcodigo(f) = txtcodigo.Text
xnombre(f) = txtnombre.Text
xdireccion(f) = txtdireccion.Text
xcredito(f) = txtcredito.Text
xdistrito(f) = cbodistrito.Text
Else
f = 20
MsgBox("el arreglo esta lleno", 64, "aviso")
End If
btnnuevo.Enabled = True
btnguardar.Enabled = False
End If
End Sub


Private Sub btnlistar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlistar.Click
lstclientes.Items.Clear()
For n = 0 To f
lstclientes.Items.Add(xcodigo(n) & xnombre(n) & vbTab & xdireccion(n) & vbTab & xcredito(n) & vbTab & xdistrito(n))
Next

End Sub

Private Sub lstclientes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstclientes.SelectedIndexChanged

End Sub

Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click
Dim xcod As String
Do
xcod = InputBox("ingrese codigo de cliente", "aviso", "")
Loop Until (xcod <> "")
Dim codigoexiste As Boolean = False

For n = 0 To f
If xcod = xcodigo(n) Then
txtcodigo.Text = xcodigo(n)
txtnombre.Text = xnombre(n)
txtdireccion.Text = xdireccion(n)
txtcredito.Text = xcredito(n)
cbodistrito.Text = xdistrito(n)
codigoexiste = True

End If
If codigoexiste = False Then
MsgBox("codigo no existe", 16, "aviso")
End If
Next
End Sub

Private Sub btnmodificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodificar.Click
If MsgBox("deseomodificar los datos", 32 + 4, "aviso") = 6 Then
For n = 0 To f
If txtcodigo.Text.Trim = xcodigo(n) Then
xnombre(n) = txtnombre.Text
xdireccion(n) = txtdireccion.Text
xcredito(n) = txtcredito.Text
xdistrito(n) = cbodistrito.Text
End If
Next
End If


End Sub

Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click

If (lstclientes.SelectedIndex > -1) Then
lstclientes.Items.RemoveAt(lstclientes.SelectedInd ex)

End If
End Sub


Private Sub cbodis_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbodis.SelectedIndexChanged
Dim n As Short
For n = 0 To cbodis.SelectedIndex - 1

Next
End Sub
End Class
  #2 (permalink)  
Antiguo 10/05/2012, 09:23
 
Fecha de Ingreso: febrero-2010
Ubicación: México
Mensajes: 738
Antigüedad: 14 años, 2 meses
Puntos: 37
Respuesta: Como eliminar el registro de un listbox?

Al parecer los estas guardando en un arreglo, no solo debes borrarlos del listbox sino que también del arreglo donde los habias guardado ya que de ahi los obtienes cuando le das listar.

Saludos.
__________________
http://ka0stj.wordpress.com/

Etiquetas: registro, vb
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:23.