Drag drop with a dotnet listview

Drag drop 3ds max files with dotnet

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.

Drag drop with a dotnet listview
Drag drop action in 3dsMax


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[0].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.


Join the discussion and tell us your opinion.

2013-04-30 at 15:45

Great stuff Klaas, a nice article and implementation.

Klaas Nienhuisreply
2013-04-30 at 19:39
– In reply to: LoneRobot

Hi Pete, thanks. Coming to the EUE this June? I’ll be speaking!

2013-05-01 at 22:09

That’s great that you are speaking. Unfortunately, due to family commitments I won’t be able to make it. I’ll look forward to your write up.

2013-05-03 at 03:19

Thank you very much Mr.Klaas , ive been searching this. Btw , you said “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” so, if I had collection array of map then I must using for loop, is that correct ?


Klaas Nienhuisreply
2013-05-03 at 07:57

Hi Fajar,
please download the entire maxscript. In it you’ll find plenty of comments to help you out. The section I’ve put in this article is just a small piece of the example. What you’re referring to is the code which prompts the popup after you drop a file on the viewport. You can only open one file at a time, so this array can only have one member.
You can show as many files in the listview. For this you’d have to use some kind of loop. This is also described further in the code itself.

2013-05-04 at 15:47

already download whole script , thanks Mr.Klass.
Will diving into it next sunday. happy holiday.

Thanks once again

Leave a reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.