VB ListBox 里的内容上下移动问题
例:List1内有以下内容aabbccabgd怎样写代码可以用鼠标选中一个内容后向上或向下拖可以改变它的位置例如我选中cc后,向上拖一格,可以和bb调换排列位置变为aac...
例:
List1 内有以下内容
aa
bb
cc
ab
gd
怎样写代码可以用鼠标选中一个内容后向上或向下拖可以改变它的位置
例如我选中 cc 后,向上拖一格,可以和 bb 调换排列位置变为
aa
cc
bb
ab
gd
如果用鼠标不行,那用按钮操作也行,先选中一项,再点击一个按钮可以向上或向下移动一位,改变排列次序。 展开
List1 内有以下内容
aa
bb
cc
ab
gd
怎样写代码可以用鼠标选中一个内容后向上或向下拖可以改变它的位置
例如我选中 cc 后,向上拖一格,可以和 bb 调换排列位置变为
aa
cc
bb
ab
gd
如果用鼠标不行,那用按钮操作也行,先选中一项,再点击一个按钮可以向上或向下移动一位,改变排列次序。 展开
3个回答
2009-09-14
展开全部
Private Sub Form_Load()
List1.AddItem "a"
List1.AddItem "b"
List1.AddItem "c"
List1.AddItem "d"
List1.AddItem "e"
End Sub
'上移
Private Sub Command1_Click()
Dim i As Integer
Dim s As String
i = List1.ListIndex
If i > 0 Then
s = List1.List(i)
List1.RemoveItem i
List1.AddItem s, i - 1
End If
End Sub
'下移
Private Sub Command2_Click()
Dim i As Integer
Dim s As String
i = List1.ListIndex
If i > -1 And i < List1.ListCount - 1 Then
s = List1.List(i)
List1.RemoveItem i
List1.AddItem s, i + 1
End If
End Sub
List1.AddItem "a"
List1.AddItem "b"
List1.AddItem "c"
List1.AddItem "d"
List1.AddItem "e"
End Sub
'上移
Private Sub Command1_Click()
Dim i As Integer
Dim s As String
i = List1.ListIndex
If i > 0 Then
s = List1.List(i)
List1.RemoveItem i
List1.AddItem s, i - 1
End If
End Sub
'下移
Private Sub Command2_Click()
Dim i As Integer
Dim s As String
i = List1.ListIndex
If i > -1 And i < List1.ListCount - 1 Then
s = List1.List(i)
List1.RemoveItem i
List1.AddItem s, i + 1
End If
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我也来凑个热闹
Dim a() As String
Dim n As Integer
Dim b As Integer
Private Sub Command1_Click()
b = List1.ListIndex
If b = 0 Then Exit Sub
temp = List1.List(b)
List1.List(b) = List1.List(b - 1)
List1.List(b - 1) = temp
List1.Selected(b) = False
List1.Selected(b - 1) = True
End Sub
Private Sub Command2_Click()
b = List1.ListIndex
If b = n - 1 Then Exit Sub
temp = List1.List(b)
List1.List(b) = List1.List(b + 1)
List1.List(b + 1) = temp
List1.Selected(b) = False
List1.Selected(b + 1) = True
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
n = List1.ListCount
ReDim a(n)
For i = 0 To n - 1
a(i) = List1.List(i)
Next i
End Sub
Dim a() As String
Dim n As Integer
Dim b As Integer
Private Sub Command1_Click()
b = List1.ListIndex
If b = 0 Then Exit Sub
temp = List1.List(b)
List1.List(b) = List1.List(b - 1)
List1.List(b - 1) = temp
List1.Selected(b) = False
List1.Selected(b - 1) = True
End Sub
Private Sub Command2_Click()
b = List1.ListIndex
If b = n - 1 Then Exit Sub
temp = List1.List(b)
List1.List(b) = List1.List(b + 1)
List1.List(b + 1) = temp
List1.Selected(b) = False
List1.Selected(b + 1) = True
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
n = List1.ListCount
ReDim a(n)
For i = 0 To n - 1
a(i) = List1.List(i)
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
呵呵已经有人把代码都写好了。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询