VB.Net Move ListBox Item Up And Down

How To Move Selected ListBox Item Up N Down In Visual Basic.Net 

VB.Net Move Selected ListBox Item Up And Down

In This VB.Net Tutorial  We Will See How To Move Selected ListBox Element Up Or Down On Button ClickIn Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class listbox_item_up_down

    Private Sub ButtonUP_Click(sender As Object, e As EventArgs) Handles ButtonUP.Click

        Dim i As Integer
        i = ListBox1.SelectedIndex

        Dim item As String
        item = ListBox1.SelectedItem.ToString()

        If i > 0 Then

            ListBox1.Items.RemoveAt(i)
            ListBox1.Items.Insert(i - 1, item)
            ListBox1.SetSelected(i - 1, True)

        End If

    End Sub

    Private Sub ButtonDOWN_Click(sender As Object, e As EventArgs) Handles ButtonDOWN.Click

        Dim i As Integer
        i = ListBox1.SelectedIndex

        Dim item As String
        item = ListBox1.SelectedItem.ToString()

        If i < ListBox1.Items.Count - 1 Then

            ListBox1.Items.RemoveAt(i)
            ListBox1.Items.Insert(i + 1, item)
            ListBox1.SetSelected(i + 1, True)

        End If

    End Sub
End Class
      
///////////////OUTPUT:





VBnet Move Selected ListBox Item Up N Down




Share this

Related Posts

Previous
Next Post »