So I am trying to only allow drag & drop to a specific folder in my listview. The problem I am having is that with the current code below is that you start the drag to a folder not allowed it gives the denied symbol, but as you drag it down over the allowed folder it shows the allowed symbol yet if you pass the folder and go into some blank space I get an error "Object reference not set to an instance of an object." even though I have not dropped anything, yet it still shows the allowed sign even though the targetpoint is not over any listview item. why does it still allow the item to be dropped even though there is no listview folder underneath it? And how do I stop from getting the exception error?
Code:Private Sub tvFolders_DragOver(ByVal sender As Object, ByVal e As DragEventArgs) Handles tvFolders.DragOver ' Retrieve the client coordinates of the mouse position. Dim targetPoint As Point = tvFolders.PointToClient(New Point(e.X, e.Y)) Try ' Select the node at the mouse position. Dim Selected As TreeNode = tvFolders.GetNodeAt(targetPoint) 'See if the targetNode is currently selected, 'if so no need to validate again ' If Selected.Text.Length > 0 Then If Not (tvFolders.SelectedNode Is Selected) Then 'Select the node currently under the cursor tvFolders.SelectedNode = Selected Debug.WriteLine(tvFolders.SelectedNode.Text) If My.Settings.Favorites.Contains(tvFolders.SelectedNode.Text) Then 'TreeNode found allow move effect e.Effect = DragDropEffects.Copy Else 'No TreeNode found, prevent move e.Effect = DragDropEffects.None End If End If Catch ex As Exception Debug.WriteLine(ex.Message) End Try End Sub




Reply With Quote