
09/05/2012, 13:35
|
| | Fecha de Ingreso: marzo-2011
Mensajes: 1
Antigüedad: 14 años Puntos: 0 | |
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 |