Private Sub tvTree_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles tvTree.ItemDrag 'Get the IName Object of the TreeNode Dim pTreeNode As TreeNode pTreeNode = e.Item Dim pclsTreeNode As clsTreeNode pclsTreeNode = pTreeNode.Tag Dim pName As IName pName = pclsTreeNode.NodeObject If Not pName Is Nothing Then 'Create IData Object Dim pDataObject As Windows.Forms.IDataObject pDataObject = New Windows.Forms.DataObject pDataObject.SetData(pName) DoDragDrop(pDataObject, DragDropEffects.All) End If End Sub
Solved! Go to Solution.
Private Sub tvTree_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles tvTree.ItemDrag Try 'Get the IName Object (I stored it in the Tag of the TreeNode) Dim pTreeNode As TreeNode pTreeNode = e.Item 'My Class where I stored the IName and some other stuff Dim pclsTreeNode As clsTreeNode pclsTreeNode = pTreeNode.Tag Dim pName As IName pName = pclsTreeNode.NodeObject If Not pName Is Nothing Then '----- For ArcMap ----- 'Put the IName in an IEnumName Dim pNameFactory As INameFactory pNameFactory = New NameFactory Dim pEnumName As IEnumName pEnumName = New NamesEnumerator Dim pEnumNameEdit As IEnumNameEdit pEnumNameEdit = pEnumName pEnumNameEdit.Add(pName) 'Create DataObject Dim pDataObject As Windows.Forms.IDataObject pDataObject = New Windows.Forms.DataObject 'To fill the DataObject you need a MemoryStream! Dim pMemoryStream As System.IO.MemoryStream pMemoryStream = New System.IO.MemoryStream(CType(pNameFactory.PackageNames(pEnumNameEdit), Byte())) pDataObject.SetData("ESRI Names", pMemoryStream) 'Fire the DragGropEvent tvTree.DoDragDrop(pDataObject, DragDropEffects.All) Else '----- For Windows Explorer ----- 'For the Internet Explorer you just need the Path of the File and put it into an Array of String Dim pArrayOfString(0) As String pArrayOfString(0) = pclsTreeNode.Path Dim pDataObject As Windows.Forms.IDataObject pDataObject = New Windows.Forms.DataObject pDataObject.SetData(DataFormats.FileDrop, pArrayOfString) tvTree.DoDragDrop(pDataObject, DragDropEffects.All) End If Catch ex As Exception DoErrorHandling(ex, Reflection.MethodInfo.GetCurrentMethod) End Try End Sub
If action = esriControlsDropAction.esriDropped Then 'If the data is from Windows Explorer. If pDataObject.CanGetFiles Then 'Get an array of file paths through the IDataObjectHelper. pFilePaths = pDataObject.GetFiles 'Loop through the array. For i = LBound(pFilePaths) To UBound(pFilePaths) 'If a valid Mx document, load it into the MapControl. If AxMapControl1.CheckMxFile(pFilePaths(i)) Then AxMapControl1.LoadMxFile(pFilePaths(i)) Else 'Get the IFileName interface and set its path. pFileName = New FileNameClass pFileName.Path = pFilePaths(i) 'Create a map layer. CreateLayer(CType(pFileName, IName)) End If Next 'If data is from ArcCatalog. ElseIf pDataObject.CanGetNames Then 'Get the IEnumName interface through the IDataObjectHelper. pEnumName = pDataObject.GetNames pEnumName.Reset() 'Get the IName interface. pName = pEnumName.Next 'Loop through the names. Do While Not pName Is Nothing 'Create a map layer. CreateLayer(pName) pName = pEnumName.Next Loop End If End If
Private Sub tvTree_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles tvTree.ItemDrag Try 'Get the IName Object (I stored it in the Tag of the TreeNode) Dim pTreeNode As TreeNode pTreeNode = e.Item 'My Class where I stored the IName and some other stuff Dim pclsTreeNode As clsTreeNode pclsTreeNode = pTreeNode.Tag Dim pName As IName pName = pclsTreeNode.NodeObject If Not pName Is Nothing Then '----- For ArcMap ----- 'Put the IName in an IEnumName Dim pNameFactory As INameFactory pNameFactory = New NameFactory Dim pEnumName As IEnumName pEnumName = New NamesEnumerator Dim pEnumNameEdit As IEnumNameEdit pEnumNameEdit = pEnumName pEnumNameEdit.Add(pName) 'Create DataObject Dim pDataObject As Windows.Forms.IDataObject pDataObject = New Windows.Forms.DataObject 'To fill the DataObject you need a MemoryStream! Dim pMemoryStream As System.IO.MemoryStream pMemoryStream = New System.IO.MemoryStream(CType(pNameFactory.PackageNames(pEnumNameEdit), Byte())) pDataObject.SetData("ESRI Names", pMemoryStream) 'Fire the DragGropEvent tvTree.DoDragDrop(pDataObject, DragDropEffects.All) Else '----- For Windows Explorer ----- 'For the Internet Explorer you just need the Path of the File and put it into an Array of String Dim pArrayOfString(0) As String pArrayOfString(0) = pclsTreeNode.Path Dim pDataObject As Windows.Forms.IDataObject pDataObject = New Windows.Forms.DataObject pDataObject.SetData(DataFormats.FileDrop, pArrayOfString) tvTree.DoDragDrop(pDataObject, DragDropEffects.All) End If Catch ex As Exception DoErrorHandling(ex, Reflection.MethodInfo.GetCurrentMethod) End Try End Sub