Microsoft
Software
Hardware
Network
Question : VB.Net move Items from ListBox to Textboxes
I have a listbox, populated with 5 items from a database. I wan't to drag items, one at a time, to 5 textboxes.
Here is my code for the source listbox:
Private Sub ListBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
EventArgs)
Handles ListBox2.MouseDown
ListBox2.DoDragDrop(ListBo
x2.Selecte
dValue.ToS
tring, DragDropEffects.Move)
End Sub
Here is code for one of the destination textboxes:
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragE
ventArgs) Handles TextBox1.DragDrop
TextBox1.AppendText(e.Data
.GetData(D
ataFormats
.StringFor
mat))
End Sub
Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragE
ventArgs) Handles TextBox1.DragEnter
TextBox1.Text = e.Data.GetData(DataFormats
.StringFor
mat)
End Sub
The destination textboxes all have AllowDrop set to True.
If I try to move an item from the listbox, it gets copied instead (item appears in textbox but does not disappear from listbox)
Answer : VB.Net move Items from ListBox to Textboxes
I figured it out. The trick is to place a statement in the target textbox's _DragDrop event, like this
ListBox1.Items.Remove(List
Box1.Selec
tedItem)
Now the dragged items are removed from the ListBox
Random Solutions
Sending a message "on behalf of" without Exchange
How Can I Trigger a Select Max Value Statement from an Access Form
Importing and appending Excel worksheets into Access Project temporary table
CSocket object in thread
VB FORMULA - Loop
Compiled code in md*B* vs md*E* ?
Sharing workbook lock for editing
What table contains company/database name - MS Dynamics GP
Intel Pro/1000 MT (Single Port) - Teaming Options Not Shown In Device Manager on Windows 2003 32-bit
Click Context Menu, opened by mshtml.IHTMLElement