INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: VB6 Code Order A Listbox  (Read 4578 times)

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20063
VB6 Code Order A Listbox
« on: October 21, 2006, 07:21:44 am »

Some Code I Wrote To Order The Listbox

1. One Checked Listbox = List1
2. Two Cmd Buttons cmdMove_Click (Index 0 and 1)

Private Sub cmdMove_Click(Index As Integer)
    Dim strTemp As String
    Dim intPos As Integer
    Dim MySelectionChecked As Boolean
    '
    If List1.ListCount > 0 Then
        strTemp = List1.List(List1.ListIndex)
        intPos = List1.ListIndex
        MySelectionChecked = False
        If List1.Selected(intPos) = True Then
            MySelectionChecked = True
        End If
        If Index = 0 Then
            If intPos - 1 >= 0 Then
                List1.RemoveItem List1.ListIndex
                List1.AddItem strTemp, intPos - 1
                List1.Selected(intPos - 1) = MySelectionChecked
            End If
        Else
            If intPos + 1 < List1.ListCount Then
                List1.RemoveItem List1.ListIndex
                List1.AddItem strTemp, intPos + 1
                List1.Selected(intPos + 1) = MySelectionChecked
            End If
        End If
    End If
End Sub
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio, Music
https://MyAAGrapevines.com
https://centercitybbs.com
Fayetteville, NC, USA

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: VB6 Code Order A Listbox
« Reply #1 on: October 21, 2006, 09:37:09 am »

I've added this to the list of useful code snippets  :)

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20063
Re: VB6 Code Order A Listbox
« Reply #2 on: October 22, 2006, 01:51:23 pm »

A Slight Mod

This Will Allow You To Move A Selected Item Up Or Down, But It Will Roll Over From The Bottom To the Top And From the Top To the Bottom.

Note This Is A Checked Listbox

Private Sub cmdMove_Click(Index As Integer)

On Error Resume next

    If List1.ListCount < 1 Then
         Exit Sub
    End If

    Dim strTemp As String
    Dim intPos As Integer
    Dim MySelectionChecked As Boolean
    '
        strTemp = List1.List(List1.ListIndex)
        intPos = List1.ListIndex

        If List1.Selected(intPos) = True Then
            MySelectionChecked = True
        Else
            MySelectionChecked = False
        End If

        If Index = 0 Then
            If intPos - 1 >= 0 Then
                List1.RemoveItem List1.ListIndex
                List1.AddItem strTemp, intPos - 1
                List1.ListIndex = intPos - 1
                List1.Selected(intPos - 1) = MySelectionChecked
            Else
                List1.RemoveItem List1.ListIndex
                List1.AddItem strTemp
                List1.ListIndex = List1.ListCount - 1
                List1.Selected(List1.ListCount - 1) = MySelectionChecked
            End If
        Else
            If intPos + 1 < List1.ListCount Then
                List1.RemoveItem List1.ListIndex
                List1.AddItem strTemp, intPos + 1
                List1.ListIndex = intPos + 1
                List1.Selected(intPos + 1) = MySelectionChecked
            Else
                List1.RemoveItem List1.ListIndex
                List1.AddItem strTemp, 0
                List1.ListIndex = 0
                List1.Selected(0) = MySelectionChecked
            End If
        End If

End Sub
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio, Music
https://MyAAGrapevines.com
https://centercitybbs.com
Fayetteville, NC, USA
Pages: [1]   Go Up