Hello all.
I have a portion of code that allows the user to drag items from one ListBox control and drop them onto another ListBox control. Up until a few days ago, I was using Visual Basic 2003 to develop this project. At that time, the drag and drop code was working. After purchasing and installing Visual Basic 2005, I converted my project to the new format. Now that I have converted, the drag and drop portion of my code no longer works.
Here is a description of the problem:
I click an item in the source ListBox and begin a drag. The mouse cursor becomes a circle with a slash through it, indicating an invalid drop target. The problem is that whenever I drag the cursor over the destination list box, the cursor never changes to indicate a valid drag target. The AllowDrop property is set in the destination list box.
Here is the code I have for drag and drop concerning the source and destination list boxes. StockItemBox is the source ListBox, StockItemCategoryBox is the destination ListBox.
Code:Private Sub StockItemBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles StockItemBox.MouseDown If StockItemBox.SelectedIndex < 0 Then Exit Sub Dim DragText As String = StockItemBox.Items(StockItemBox.SelectedIndex) StockItemBox.DoDragDrop(DragText, DragDropEffects.Move) End SubCode:Private Sub StockItemCategoryBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles StockItemCategoryBox.DragEnter If (e.Data.GetDataPresent(DataFormats.Text)) Then ' Display the copy cursor. e.Effect = DragDropEffects.Copy Else ' Display the no-drop cursor. e.Effect = DragDropEffects.None End If End SubThe StockItemCategoryBox_DragDrop method is never called.Code:Private Sub StockItemCategoryBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles StockItemCategoryBox.DragDrop 'extract the dropped text Dim TextDropped As String = e.Data.GetData(DataFormats.Text).ToString MsgBox(TextDropped) End Sub
I'm not sure if it makes a difference, but the form that these controls are located on is displayed using a ShowDialog call.
Anyone have any suggestions? Is there something I am missing here? It is weird that the code worked fine with the 2003 project but not the newly converted project.


Reply With Quote
