Advertisement
5_2007-2008 Miscellaneous #177715

Listbox Reorder

A function that will allow you to move the selected item in any listbox up or down in the listbox.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Function MoveListItem(LstBox As Object, WhatDir As Integer)
  'WhatDir = 0 up, 1 down
  'Returns -1 if nothing is selected
  'Returns current position otherwise
  Dim CurPos As Integer, CurData As String, NewPos As Integer
  CurPos = LstBox.ListIndex
  If CurPos < 0 Then MoveListItem = -1: Exit Function
  CurData = LstBox.List(CurPos)
  If WhatDir = 0 Then
    'Move Up
    If (CurPos - 1) < 0 Then NewPos = (LstBox.ListCount - 1) Else NewPos = (CurPos - 1)
  Else
    'Move Down
    If (CurPos + 1) > (LstBox.ListCount - 1) Then NewPos = 0 Else NewPos = (CurPos + 1)
  End If
  LstBox.RemoveItem (CurPos)
  LstBox.AddItem CurData, NewPos
  LstBox.Selected(NewPos) = True
  MoveListItem = NewPos
End Function
Original Comments (3)
Recovered from Wayback Machine