[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1548
  • Last Modified:

Change Order by ListBox Items by Pressing Button

I want to have a button next to a listbox that will move the selected item down one in the overall order of items in the list box.  What is the best way to handle.
2 Solutions
You could create a new ListItem from the SelectedItem (lb.SelectedItem) then get the item's index position (lb.SelectedIndex) then remove that item from the items collection (lb.Items.RemoveAt), then add the newly created ListItem back into the Item collection ( lb.Items.Insert( int index, ListItem item) ) where you want it.
Alpesh PatelCommented:
here is the scenario that you can apply on the click event of command button

    Dim l_ListItem As New ListItem
        l_ListItem = ListBox1.SelectedItem
        Dim l_intItem As Integer

        l_intItem = ListBox1.SelectedIndex

        If Not l_intItem = ListBox1.Items.Count - 1 Then
            l_intItem = l_intItem + 1
        End If
        ListBox1.Items.Insert(l_intItem, l_intItem)
cadwal01Author Commented:
You are both correct.  Key was getting it as a listitem.

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now