|
-
Apr 15th, 2001, 10:31 PM
#1
Thread Starter
New Member
I want to allow a user to reorder items in a listbox. For example, clicking on a button should move the currently selcted item in a listbox up one position in the list. It should remain selected so that the user can contiune clicking the button repeatedly.
-
Apr 15th, 2001, 10:34 PM
#2
Code:
Private Sub List1_Click()
Dim strTemp As String
strTemp = List1.List(List1.ListIndex)
List1.RemoveItem List1.ListIndex
List1.AddItem strTemp,0
List1.Selected(0) = True
End Sub
there's probably a faster way, but its late
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 15th, 2001, 10:37 PM
#3
Frenzied Member
lol. that code doesnt work.
-
Apr 15th, 2001, 10:38 PM
#4
Yawn... *streches a little...*
what part doesn't work? I'm not looking at VB right now...
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 15th, 2001, 10:42 PM
#5
Frenzied Member
with this code the selected item goes to the top of the list...
-
Apr 15th, 2001, 10:45 PM
#6
damn, I gotta learn to read better, I thought thats what he was looking for, my mistake...
Code:
Private Sub List1_Click()
Dim strTemp As String
Dim intPos As Integer
strTemp = List1.List(List1.ListIndex)
intPos = List1.ListIndex - 1
List1.RemoveItem List1.ListIndex
If intPos >= 0 Then
List1.AddItem strTemp,intPos
List1.Selected(intPos) = True
Else
List1.AddItem strTemp,0
List1.Selected(0) = True
End If
End Sub
does that work guys?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 15th, 2001, 10:51 PM
#7
Frenzied Member
it works with one correction, sorry man, ... who am i to correct you...
Private Sub Command1_Click()
Dim strTemp As String
Dim intPos As Integer
strTemp = List1.List(List1.ListIndex)
intPos = List1.ListIndex - 1
List1.RemoveItem List1.ListIndex
If intPos >= 0 Then
List1.AddItem strTemp, intPos
List1.Selected(intPos) = True
Else
List1.AddItem strTemp, 0
List1.Selected(0) = True
End If
End Sub
use a command_click event instead of a list_click event or you will get a "Out of stack space" error
-
Apr 15th, 2001, 10:55 PM
#8
Originally posted by zuperman
it works with one correction, sorry man, ... who am i to correct you...
I make mistakes like everybody. Thanks for pointing that out
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 16th, 2001, 12:13 AM
#9
Frenzied Member
hehe
I like correcting him! It makes my lameass feel better about my self!
Just kidding!! hehe
-
Apr 16th, 2001, 12:16 AM
#10
Frenzied Member
-
Oct 20th, 2006, 07:18 PM
#11
New Member
Re: Absolute beginner's question
This Is With Up And Down Buttons With Slight Mods To The Code.
Private Sub cmdMove_Click(Index As Integer)
Dim strTemp As String
Dim intPos As Integer
Dim MySelectionChecked As Boolean
'
If MCListing(1).ListCount > 0 Then
strTemp = MCListing(1).List(MCListing(1).ListIndex)
intPos = MCListing(1).ListIndex
MySelectionChecked = False
If MCListing(1).Selected(intPos) = True Then
MySelectionChecked = True
End If
If Index = 0 Then
If intPos - 1 >= 0 Then
MCListing(1).RemoveItem MCListing(1).ListIndex
MCListing(1).AddItem strTemp, intPos - 1
MCListing(1).Selected(intPos - 1) = MySelectionChecked
End If
Else
If intPos + 1 < MCListing(1).ListCount Then
MCListing(1).RemoveItem MCListing(1).ListIndex
MCListing(1).AddItem strTemp, intPos + 1
MCListing(1).Selected(intPos + 1) = MySelectionChecked
End If
End If
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|