VB.NET如何实现表间拖放
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要为大家展示了"VB.NET如何实现表间拖放",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"VB.NET如何实现表间拖放"这篇文章吧。VB.NET
千家信息网最后更新 2026年11月02日VB.NET如何实现表间拖放
这篇文章主要为大家展示了"VB.NET如何实现表间拖放",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"VB.NET如何实现表间拖放"这篇文章吧。
VB.NET表间拖放
VB.NET表间拖放有一个情况是从一个列表移动项目到另一个列表。这种情况下拖放将变得更加简单。向窗体中添加两个ListView控件,并把他们的AllowDrop、Multiselect、View属性分别设置成True、True、List。并添加如下代码:
Private Sub ListView_ItemDrag(ByVal sender As Object, ByVal e As _ System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag, _ ListView2.ItemDrag Dim myItem As ListViewItem Dim myItems(sender.SelectedItems.Count - 1) As ListViewItem Dim i As Integer = 0 ' Loop though the SelectedItems collection for the source. For Each myItem In sender.SelectedItems ' Add the ListViewItem to the array of ListViewItems. myItems(i) = myItem ii = i + 1 Next ' Create a DataObject containg the array of ListViewItems. sender.DoDragDrop(New _ DataObject(System.Windows.Forms.ListViewItem(), myItems), _ DragDropEffects.Move) End Sub Private Sub ListView_DragEnter(ByVal sender As Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter, _ ListView2.DragEnter ' Check for the custom DataFormat ListViewItem array. If e.Data.GetDataPresent(System.Windows.Forms.ListViewItem()) Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As _ System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop, _ ListView2.DragDrop Dim myItem As ListViewItem Dim myItems() As ListViewItem = _ e.Data.GetData(System.Windows.Forms.ListViewItem()) Dim i As Integer = 0 For Each myItem In myItems ' Add the item to the target list. sender.Items.Add(myItems(i).Text) ' Remove the item from the source list. If sender Is ListView1 Then ListView2.Items.Remove(ListView2.SelectedItems.Item(0)) Else ListView1.Items.Remove(ListView1.SelectedItems.Item(0)) End If ii = i + 1 Next End Sub
你可能不明白为什么这个例子中用的是ListView控件而不是ListBox控件,这个问题题的好,因为ListBox控件不支持多项拖放。ListView和TreeView控件有个ItemDrag事件。上面的例子中,一个ItemDrag事件句柄覆盖了两个控件,并在列在Handles从句。Sender参数表明哪个控件正在初始化Drag。因为DataFormats类没有ListViewItem类型成员,数据必须传递给一个系统类型。ItemDrag创建了一个ListViewItem类型的数组,并用一个循环来遍历SelectedItem集合。在DoDragDrop方法中,创建了一个新的DataObject并用数组来来对它进行操作。可以用这种方法来拖放任何系统类型。
以上是"VB.NET如何实现表间拖放"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
控件
类型
内容
篇文章
两个
事件
例子
情况
数组
方法
系统
学习
帮助
中用
从句
代码
参数
句柄
属性
成员
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
上海互联网科技有限公司
上海挚品互联网科技
世界互联网领先科技成果
兼蜜互联网科技
苏州大垚互联网科技
互联网科技公司介绍
互联网科技生活的内容
成都玖崟互联网科技有限公司乐商圈怎么样
中盈科技互联网信息有限公司
互联网科技有哪些公司
湖北码尼互联网科技有限公司电话
移动互联网科技公司
互联网行业科技股
互联网科技创新的路径
互联网科技大赛获奖感言
众安科技工业互联网合作
每天都有哪些好的互联网科技
广州燕处互联网科技有限公司
杭州科技互联网公司有哪些
承德科技产业互联网平台
深圳市人人互联网科技有限公司
互联网科技公司经营范围
湖南永感互联网科技有限公司
紫鲸互联网科技
互联网科技排名
上海喔噻互联网科技
汽车互联网创新科技园
互联网公司科技股
互联网风格科技公司名称
山东亿川互联网科技有限责任公司