拖放数据操作:从DataGridView拖放数据到ListBox中。
来源:互联网 发布:mac装双系统多少钱 编辑:程序博客网 时间:2024/04/28 17:33
从DataGridView拖放选中的行到ListBox中。项目中要用到拖放操作,在网上找不到,不过研究了许多别人的代码。自己写的简单代码。
界面中要一个DataGridView1, ListBox1 ,两个Button。
代码如下:
Public Class FrmDvDragClass FrmDvDrag
Private Sub FrmDvDrag_Load()Sub FrmDvDrag_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.Columns.Add("code", "code")
Me.DataGridView1.Columns.Add("name", "name")
Me.DataGridView1.AllowDrop = True
Me.ListBox1.AllowDrop = True
Me.DataGridView1.Rows.Add("1", "23423")
Me.DataGridView1.Rows.Add("2", "asaer")
End Sub
Private Sub DataGridView1_MouseDown()Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left And Me.DataGridView1.SelectedRows.Count > 0 Then
Dim SelRow As DataGridViewSelectedRowCollection
SelRow = Me.DataGridView1.SelectedRows
Me.DataGridView1.DoDragDrop(SelRow, DragDropEffects.Copy)
End If
End Sub
Private Sub ListBox1_DragEnter()Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
If e.Data.GetDataPresent(GetType(DataGridViewSelectedRowCollection)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListBox1_DragDrop()Sub ListBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
If e.Data.GetDataPresent(GetType(DataGridViewSelectedRowCollection)) Then
Dim dr As DataGridViewSelectedRowCollection
dr = e.Data.GetData(GetType(DataGridViewSelectedRowCollection))
For i As Integer = 0 To dr.Count - 1
Me.ListBox1.Items.Add(dr.Item(i).Cells(0).Value)
Next
End If
End Sub
Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.ListBox1.Items.Clear()
End Sub
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
Private Sub FrmDvDrag_Load()Sub FrmDvDrag_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.Columns.Add("code", "code")
Me.DataGridView1.Columns.Add("name", "name")
Me.DataGridView1.AllowDrop = True
Me.ListBox1.AllowDrop = True
Me.DataGridView1.Rows.Add("1", "23423")
Me.DataGridView1.Rows.Add("2", "asaer")
End Sub
Private Sub DataGridView1_MouseDown()Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left And Me.DataGridView1.SelectedRows.Count > 0 Then
Dim SelRow As DataGridViewSelectedRowCollection
SelRow = Me.DataGridView1.SelectedRows
Me.DataGridView1.DoDragDrop(SelRow, DragDropEffects.Copy)
End If
End Sub
Private Sub ListBox1_DragEnter()Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter
If e.Data.GetDataPresent(GetType(DataGridViewSelectedRowCollection)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListBox1_DragDrop()Sub ListBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
If e.Data.GetDataPresent(GetType(DataGridViewSelectedRowCollection)) Then
Dim dr As DataGridViewSelectedRowCollection
dr = e.Data.GetData(GetType(DataGridViewSelectedRowCollection))
For i As Integer = 0 To dr.Count - 1
Me.ListBox1.Items.Add(dr.Item(i).Cells(0).Value)
Next
End If
End Sub
Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.ListBox1.Items.Clear()
End Sub
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
- 拖放数据操作:从DataGridView拖放数据到ListBox中。
- VB.Net程序设计:拖放数据操作-从ListBox中拖放数据到ListBox 中
- VB.Net程序设计:拖放数据操作-ListView拖放数据到TextBox中
- VB.Net程序设计:从DataGridView拖放一行数据到TreeView中的某个节点
- listbox实现拖放操作
- 使DataGridView支持数据拖放(DragDrop)
- Drag拖放数据操作示例
- DataGridView鼠标的拖放操作及单元格编辑结束数据复制与单元格单击数据粘贴及两个DataGridView相互拖放操作
- 拖放操作-实现Treeview到Treeview和DataGridView到Treeview
- 控件之间拖放操作(二)-----实现Treeview节点到DataGridView
- Control study -> Drag拖放数据操作示例
- Control study -> Drag拖放数据操作示例
- Control study -> Drag拖放数据操作示例
- qt拖放 控件之间拖放 自定义数据
- 用MFC实现文件拖放到ListBox
- VB.Net程序设计:拖放Datagridview到另外一个Datagridview基本操作
- VB.Net程序设计:拖放数据操作-如何拖放自定义的数据类型
- Silverlight ListBox拖放
- 浅谈OpenWengo
- 面向对象分析与设计技术
- 提高百度排名
- 轻轻松松提高百度排名-作弊篇
- 选择多选筐
- 拖放数据操作:从DataGridView拖放数据到ListBox中。
- iis+tomcat
- java的日期处理
- 进行自动备份的脚本
- RedHat Fedora 8详细安装过程 PDF文件
- 新Web应用的成熟是否意味着Web3.0诞生?
- OpenCms7.0.3安装 For MS SQLServer2000
- 异构(分布式)管理系统的数据报送与同步解决方案
- 软件架构师成长之路