VB.Net程序设计:ListBox拖动排序两个ListBox的 *** 作

VB.Net程序设计:ListBox拖动排序两个ListBox的 *** 作,第1张

概述VB.Net程序设计:ListBox拖动排序代码和两个ListBox *** 作 常用于:左边的listbox添加到右边的listbox。 简单代码。供自己用。    'Dim _listA, _listB As New List(Of String) 'Dim indexofsource As Integer '//拖动的起始索引 'Dim indexoftarget As

VB.Net程序设计:ListBox拖动项排序代码和两个ListBox *** 作

常用于:左边的ListBox添加到右边的ListBox。

简单代码。供自己用。

    'Dim _ListA,_ListB As New List(Of String)    'Dim indexofsource As Integer  '//拖动的起始索引    'Dim indexoftarget As Integer  '//拖动的结束索引'......Private Sub LstB_DragDrop(ByVal sender As Object,ByVal e As System.windows.Forms.DragEventArgs) Handles LstB.DragDrop        Dim lb As ListBox = CType(sender,ListBox)        indexoftarget = lb.IndexFromPoint(lb.PointToClIEnt(New Point(e.X,e.Y)))        If (indexoftarget <> ListBox.NoMatches) Then            Dim temp As String = lb.Items(indexoftarget).ToString()            lb.Items(indexoftarget) = lb.Items(indexofsource)            lb.Items(indexofsource) = temp            lb.Selectedindex = indexoftarget        End If    End Sub    Private Sub LstB_DragOver(ByVal sender As Object,ByVal e As System.windows.Forms.DragEventArgs) Handles LstB.DragOver        '//拖动源和放置的目的地一定是一个ListBox        If (e.Data.GetDataPresent(GetType(Integer)) And (CType(sender,ListBox)).Equals(Me.LstB)) Then            e.Effect = DragDropEffects.Move        Else            e.Effect = DragDropEffects.None        End If    End Sub    Private Sub LstB_MouseMove(ByVal sender As System.Object,ByVal e As System.windows.Forms.MouseEventArgs) Handles LstB.MouseMove        If e.button = windows.Forms.Mousebuttons.left Then            indexofsource = (CType(sender,ListBox)).IndexFromPoint(e.X,e.Y)            If (indexofsource <> ListBox.NoMatches) Then 'NoMatches=-1                'CType(sender,ListBox).DoDragDrop(CType(sender,ListBox).Items(indexofsource).ToString(),DragDropEffects.All)                CType(sender,ListBox).DoDragDrop(indexofsource,DragDropEffects.All)            End If        End If    End Sub    Private Sub BtnAdd_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnAdd.Click        If Me.LstA.SelectedItems.Count = 1 Then            If Me._ListB.Contains(Me._ListA.Item(Me.LstA.Selectedindex)) = False Then                Me._ListB.Add(Me._ListA.Item(Me.LstA.Selectedindex))                ShowListB()            End If        End If    End Sub    Private Sub BtnAddAll_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnAddAll.Click        _ListB.Clear()        For Each s As String In _ListA            _ListB.Add(s)        Next        ShowListB()    End Sub    Private Sub BtnRemove_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnRemove.Click        If Me.LstB.SelectedItems.Count = 1 Then            _ListB.RemoveAt(Me.LstB.Selectedindex)            ShowListB()        End If    End Sub    Private Sub BtnRemoveAll_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnRemoveAll.Click        _ListB.Clear()        Me.LstB.Items.Clear()    End Sub
总结

以上是内存溢出为你收集整理的VB.Net程序设计:ListBox拖动排序两个ListBox的 *** 作全部内容,希望文章能够帮你解决VB.Net程序设计:ListBox拖动排序两个ListBox的 *** 作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1290715.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论

登录后才能评论

评论列表(0条)

    保存