Lonerobot has written an excellent article about dragging and dropping max files from dotnet controls into the viewport just like you would drag drop a max file from an explorer window. I’m following this up by providing an example on how to do this from a listview control.
Get the script here Or get it on github
Drop max files with a listview
Lonerobot describes the peculiarities about dropping a maxfile. The example he uses can be transferred to using a listview. With a little help from Marco Brunetta on cgTalk this works flawlessly. I’ve written an example which displays the recent documents and enables you to drop them onto a viewport. This listview takes any array of maxfiles, or texturefiles for that matter. So you’re free to edit this script to suit your needs.
To reiterate the work by lonerobot, you have to take a very specific route if you want to invoke the drop-menu. Here’s the code of the event handler:
local theFilePath = sender.SelectedItems.Item.tag.value --the filepath for the dropped item --place the max-string into a dotnet-string-array local dropfilePath = dotnetobject "System.String" 1 --this isn't a string, but an array of strings with one member dropfilePath.setvalue theFilePath 0 --feed the string into a special dataObject local dataObj = dotnetobject "DataObject" ((dotnetclass "DataFormats").filedrop) dropfilePath sender.dodragdrop dataobj ((dotnetclass "DragDropEffects").Copy)
You can’t just give the filepath as a string to the dataObject. You need to put your string into a dotnet string-array of one member.