如何在列表框中上下移动数据 [英] How to move datas in a list box to up and down

查看:67
本文介绍了如何在列表框中上下移动数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有国家/地区名称的列表框,我也有上下按钮来移动国家/地区。当我点击向上按钮时,将所选字段向上移动到一个位置,当单击向下按钮时,将所选项目向下移动一个位置



plz帮助我

解决方案

请看我对这个问题的评论并选择一些人性化的UI设计,用户友好而不是用户恶意。

请参阅,进入特别是: https:// msdn。 microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist%28v=vs.110%29.aspx [ ^ ]。



这是你可以改变选择的方法: https://msdn.microsoft.com/en-us/library/system.web.ui.webco ntrols.dropdownlist.selectedindex(v = vs.110).aspx [ ^ ]。



但你很难需要它(除非你想要多余的按钮的想法),因为用户想要使用这个非常控制来控制某些控件的状态。因此,您只需获得一个选定的值: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v = vs.110).aspx [ ^ ]。



-SA


 私有  Sub  btnup_Click( ByVal 发​​件人作为 对象 ByVal  e  As  System.EventArgs)句柄 btnup.Click 



Dim item As 对象 = lst1.SelectedItem
如果 项目 没什么 然后
Dim index 作为 整数 = lst1.Items.IndexOf(item)
如果 index> 0 然后
lst1.Items.RemoveAt(index)
index - = < span class =code-digit> 1
lst1.Items.Insert(index,item)
lst1.SelectedIndex = index
结束 如果
结束 如果
结束 Sub

私有 Sub btndown_Click( ByVal sender As 对象 ByVal e As System.EventArgs)句柄 btndown.Click
Dim item <跨度 class =code-keyword>作为 对象 = lst1.SelectedItem
如果 没什么 然后
Dim index As 整数 = lst1.Items.IndexOf(item)
如果 index< lst1.Items.Count - 1 然后
lst1.Items.RemoveAt(index)
index + = 1
lst1.Items.Insert(index,item)
lst1.SelectedIndex = index
结束 如果
结束 如果
结束 Sub


I have a list box with country names and also i have up and down buttons to move the countries . When i click on the up button move the selected field to one position upward and when click on the down button move the selected item one position downward

plz help me

解决方案

Please see my comment to the question and choose some humane UI design, user-friendly instead of user-hostile.
Please see, in particular: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist%28v=vs.110%29.aspx[^].

This is how you can change the selection: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.selectedindex(v=vs.110).aspx[^].

But you will hardly need it (unless you want to come to the idea of superfluous buttons), because the user wants to control the state of some control using this very control. So, you will really need just to get a selected value: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v=vs.110).aspx[^].

—SA


Private Sub btnup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnup.Click



        Dim item As Object = lst1.SelectedItem
        If Not item Is Nothing Then
            Dim index As Integer = lst1.Items.IndexOf(item)
            If index > 0 Then
                lst1.Items.RemoveAt(index)
                index -= 1
                lst1.Items.Insert(index, item)
                lst1.SelectedIndex = index
            End If
        End If
    End Sub

    Private Sub btndown_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndown.Click
        Dim item As Object = lst1.SelectedItem
        If Not item Is Nothing Then
            Dim index As Integer = lst1.Items.IndexOf(item)
            If index < lst1.Items.Count - 1 Then
                lst1.Items.RemoveAt(index)
                index += 1
                lst1.Items.Insert(index, item)
                lst1.SelectedIndex = index
            End If
        End If
    End Sub


这篇关于如何在列表框中上下移动数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆