在VB中的列表框中移动项目 [英] Move item in Listbox in VB
本文介绍了在VB中的列表框中移动项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在列表框中遇到问题
我想用命令按钮移动项目,如向上按钮,将所选项目向上移动一步。同样,向下按钮将所选项目向下移动一步。
I want to move item with command buttons like up button move the selected item one step up . Similarly , down button move the selected item to one step down.
顶部按钮将所选项目移动到列表顶部
Top button move the selected item to to the top of List
推荐答案
向上移动
Dim si As Integer = ListBox1.SelectedIndex
If si < 1 Then Return
Dim item As Object = ListBox1.Items(si)
si = si - 1
ListBox1.Items.Remove(item)
ListBox1.Items.Insert(si, item)
ListBox1.SelectedIndex = si
下移
Move down
Dim si As Integer = ListBox1.SelectedIndex
If si = -1 Or si = ListBox1.Items.Count - 1 Then Return
Dim item As Object = ListBox1.Items(si)
si = si + 1
ListBox1.Items.Remove(item)
ListBox1.Items.Insert(si, item)
ListBox1.SelectedIndex = si
这篇关于在VB中的列表框中移动项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文