1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
Public Class Form2
Dim liste As New List(Of ClassExemple)
Dim bds As New BindingSource
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
liste.Add(New ClassExemple("one", 2))
liste.Add(New ClassExemple("two", 3))
liste.Add(New ClassExemple("three", 4))
liste.Add(New ClassExemple("four", 5.0))
liste.Add(New ClassExemple("five", 5.0))
liste.Add(New ClassExemple("six", 6.0))
liste.Add(New ClassExemple("seven", 7))
liste.Add(New ClassExemple("eight", 8))
liste.Add(New ClassExemple("nine", 9))
liste.Add(New ClassExemple("ten", 10))
bds.DataSource = liste
DataGridView1.DataSource = bds
ListBox1.AllowDrop = True
End Sub
Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
DataGridView1.DoDragDrop(DataGridView1.SelectedRows, DragDropEffects.Copy Or DragDropEffects.Copy)
End Sub
Private 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(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
Dim rows As DataGridViewSelectedRowCollection = CType(e.Data.GetData(GetType(DataGridViewSelectedRowCollection)), DataGridViewSelectedRowCollection)
Dim ligne As String
For Each row As DataGridViewRow In rows
ligne = String.Empty
For Each item As DataGridViewCell In row.Cells
ligne = ligne & " " & item.Value.ToString
Next
ListBox1.Items.Add(ligne)
DataGridView1.Rows.Remove(row)
Next
'CODE MIS EN COMMENT... POUR DROPPER LA CELLULE 0 UNIQUEMENT
'For Each row As DataGridViewRow In rows
' ListBox1.Items.Add(row.Cells(0).Value)
' DataGridView1.Rows.Remove(row)
'Next
End Sub
End Class
Public Class ClassExemple
Public Sub New(ByVal p1 As String, ByVal p2 As Integer)
Prop1 = p1
Prop2 = p2
End Sub
Public Property Prop1() As String
Public Property Prop2() As String
End Class |
Partager