Visual Basic - Subir y Bajar elementos en un listbox

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

Subir y Bajar elementos en un listbox

Publicado por ricaurtem (313 intervenciones) el 22/08/2007 20:28:44
Hola como puedo hacer para bajar y subir elementos en un listbox, por ejemplo tengo una lista de 5 numeros

1
2
3
4
5

y tengo dos botones uno para subir y el otro para bajar, cuando seleeciono 4 y lo quiero mover mas arriba

1
4
2
3
5

como hago??
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Que buena!

Publicado por P. J. (173 intervenciones) el 22/08/2007 20:51:27
Aja, esas preguntas son buenas, alli fastidiando al vb me salio esto.

Agrega 1 listbox y 2 botones y prueba:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Private Sub cmdBajar_Click()
Dim intIndex As Integer
intIndex = List1.List(List1.ListIndex)
If Not Me.List1.ListIndex = Me.List1.ListCount - 1 Then
    List1.List(List1.ListIndex) = List1.List(List1.ListIndex + 1)
    List1.List(List1.ListIndex + 1) = intIndex
    List1.ListIndex = List1.ListIndex + 1
End If
End Sub
 
Private Sub cmdSubir_Click()
Dim intIndex As Integer
intIndex = List1.List(List1.ListIndex)
If Not Me.List1.ListIndex = 0 Then
    List1.List(List1.ListIndex) = List1.List(List1.ListIndex - 1)
    List1.List(List1.ListIndex - 1) = intIndex
    List1.ListIndex = List1.ListIndex - 1
End If
End Sub

Espero te sea util. Suerte!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Que buena!

Publicado por RICAURTEM (313 intervenciones) el 22/08/2007 20:53:21
gracias, recien ya habia hecho algo casi igual, es muy parecido
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Que buena!

Publicado por JAVIER PINILLA (1 intervención) el 20/05/2011 16:05:22
lo he probado pero solo desplaza los elementos de la primera columna, los demás los deja quietos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

No sirve para nada

Publicado por Richard Uchuya Ramos (2 intervenciones) el 20/05/2015 16:21:37
Ese código puede ser de visual 4 5 o 6.1 pero no funciona en visual studio 2015 .
¿Que acaso nadie tiene el código para la versión actual?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar

Excelente

Publicado por richard martin uchuya ramos (2 intervenciones) el 23/05/2015 00:53:40
hice eso y mi PC en un minuto se apago y cuanndo la volvi a encender estaba recontra lenta:

el verdadero codigo es:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Private Sub SubeItem_Click(sender As Object, e As EventArgs) Handles SubeItem.Click
        On Error Resume Next
        Dim ItemTemporal As String
        Dim ItemTemporal2 As String
        Dim N As Integer
        Dim N2 As Integer
        Dim NF As Integer
        N = Lista.SelectedIndex
        N2 = N - 1
        Lista.SelectionMode = SelectionMode.One
        ItemTemporal = Lista.SelectedItem
        ItemTemporal2 = Lista.Items.Item(N2)
        N = N - 1
        Lista.Items.Item(N) = ItemTemporal
        NF = Lista.SelectedIndex.ToString()
        Lista.Items.Item(NF) = ItemTemporal2
        Lista.SelectedIndex = Lista.SelectedIndex - 1
        ActualTrack.Text = Lista.SelectedIndex + 1
        Dim ListaTOTAL As Integer
        ListaTOTAL = Lista.Items.Count
        If Lista.SelectedIndex = "-1" Then
            Lista.SelectedIndex = ListaTOTAL - 1
            ActualTrack.Text = Lista.Items.Count
        End If
        GuardarLista.Enabled = True
    End Sub
 
    Private Sub AbajoItem_Click(sender As Object, e As EventArgs) Handles AbajoItem.Click
        On Error Resume Next
        Dim ItemTemporal As String
        Dim ItemTemporal2 As String
        Dim N As Integer
        Dim N2 As Integer
        Dim NF As Integer
        N = Lista.SelectedIndex
        N2 = N + 1
        Lista.SelectionMode = SelectionMode.One
        ItemTemporal = Lista.SelectedItem
        ItemTemporal2 = Lista.Items.Item(N2)
        N = N + 1
        Lista.Items.Item(N) = ItemTemporal
        NF = Lista.SelectedIndex.ToString()
        Lista.Items.Item(NF) = ItemTemporal2
        ActualTrack.Text = Lista.SelectedIndex + 2
        Dim ListaTOTAL As Integer
        ListaTOTAL = Lista.Items.Count
        If Lista.SelectedIndex = ListaTOTAL - 1 Then
            Lista.SelectedIndex = "0"
            ActualTrack.Text = "1"
        Else
            Lista.SelectedIndex = Lista.SelectedIndex + 1
        End If
        GuardarLista.Enabled = True
    End Sub
 
    Private Sub PrimeroItem_Click(sender As Object, e As EventArgs) Handles PrimeroItem.Click
        On Error Resume Next
        Dim ItemTemporal As String
        Dim N As Integer
        N = Lista.SelectedIndex
        Lista.SelectionMode = SelectionMode.One
        Dim curItem As Integer = Lista.SelectedIndex.ToString()
        Dim index As Integer = Lista.FindString(curItem)
        Lista.SetSelected(curItem, True)
        ItemTemporal = Lista.SelectedItem
        Lista.Items.RemoveAt(curItem)
        Lista.Items.Item(-1) = ItemTemporal
        GuardarLista.Enabled = True
        ActualTrack.Text = "1"
    End Sub
 
    Private Sub ÚltimoItem_Click(sender As Object, e As EventArgs) Handles ÚltimoItem.Click
        On Error Resume Next
        Dim ItemTemporal As String
        Dim N As Integer
        N = Lista.SelectedIndex
        Lista.SelectionMode = SelectionMode.One
        Dim curItem As Integer = Lista.SelectedIndex.ToString()
        Dim index As Integer = Lista.FindString(curItem)
        Lista.SetSelected(curItem, True)
        ItemTemporal = Lista.SelectedItem
        Lista.Items.RemoveAt(curItem)
        Lista.SelectedIndex = N - 1
        Lista.Items.Add(ItemTemporal)
        Dim ListaTOTAL As Integer
        ListaTOTAL = Lista.Items.Count
        Lista.SelectedIndex = ListaTOTAL - 1
        ActualTrack.Text = Lista.Items.Count
        GuardarLista.Enabled = True

Y MEJOR NO VAS POR AHI ENGAÑANDO INCAUTOS
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar