Quantcast
Viewing all articles
Browse latest Browse all 10

Simple illustration of drag and drop Events in vb.net

 
The following example demonstrates how to perform a drag and drop operation between Listbox and Textbox controls in vb.net

this example requires one windows form that contains one listbox controls named ListBox1 and one textbox named TextBox1, Use the toolbox to add these controls to Form1. Change the AllowDrop property of both ListBox1 and TextBox1 to True in the Properties window.

Generate method handler for Load event of Form1 and use this code for binding items to ListBox1 :

  1. Private Sub Listbox1_Mousedown(ByVal Sender As Object, _
  2.                                        ByVal e As System.Windows.Forms.MouseEventArgs) Handles Listbox1.Mousedown
  3.             Dim Selecteditems As String
  4.             For i As Integer = 0 To Listbox1.Selecteditems.Count 1
  5.                 Selecteditems = Selecteditems & "," & Listbox1.Selecteditems.Item(i)
  6.             Next
  7.             Listbox1.Dodragdrop(Selecteditems, DragDropEffects.Copy Or DragDropEffects.Move)
  8. End Sub
  1.      Private Sub TextBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
  2.             e.Effect = DragDropEffects.Copy
  3.     End Sub
  4.      
  5.     Private Sub TextBox1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
  6.             TextBox1.Text = e.Data.GetData(DataFormats.Text).ToString
  7.     End Sub

Viewing all articles
Browse latest Browse all 10

Trending Articles