BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Dragging and dropping an item from a WinForm list control to a Visio diagram

Started by Visisthebest, November 20, 2022, 11:05:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


In a Microsoft Office VSTO solution I would like to create drag-and-drop functionality to drag an item from a modern WinForm list(view) like:

To summarize the functionality:
1. User drags a list item onto the Visio diagram page
2. My code is triggered by the event, reads the info from the list item dropped and takes care of dropping the specific shape with the specific information required.

I found this info:

Is there a more detailed article somewhere on a website that I can read to understand better how to add this functionality? Thank you for your guidance!
Visio 2021 Professional


I've posted that answer something like 8 years ago, so may not remember the details :) Also, there is probably no article or anything from my side, just that.
But that code alone may actually be good enough, you just add a form with a list and add a handler for the list's "ItemDrag" event, and that should be it.

I've just done that actually, as a blank-new project:

Considering your steps, I think the code needs to be "in the loop" before the shape lands on the page, then it may be already too late.
For one thing, when the user "drags", Visio shows a "preview" of what the result would be if he dropped (a "live preview").

So, you may need to "configure" the shape not when user already "drops" but when he just starts dragging.
You can adjust some properties on drop of course, but replacing the whole shape on drop would probably be a bad idea.

Dropping a shape that is NOT coming from some sort of a Visio stencil (like in the sample above - keep in mind it can be your custom stencil and your custom shape from the stencil as well),
but is built on the fly by code out of thin air in memory, would be much harder to implement, as far as I see.


Thank you Nikolay I will experiment with this to see what I can get to work and what is possible!

Showing a preview of the shape I'd like to use while dragging (over the Visio page) would be great for the user experience, clearer for the user what is happening.
Visio 2021 Professional



Amazing Nikolay not at my desk today but will try your code Monday really cool exactly what I'm looking for!   :D :D
Visio 2021 Professional


After replacing the code signing certificate the VS solution builds and it works perfectly thank you Nikolay!

I will try to apply it with the Syncfusion list view control but it should work the same:

You might not know this Nikolay but you can get all the Syncfusion WinForm and WPF controls for free as a small developer with this license:

(as well as all their other great controls and software!)

Only for small business and not for custom development, but for the Visio add-ins you distribute and sell you are fully covered with this free license!

Amazing I love the SyncFusion people!
Visio 2021 Professional


Ah right, probably forgot to remove that auto-generated certificate Visual Studio adds automatically when creating new project.
Will remove from the repo.

The SyncFusion controls look nice. Hopefully they also do have something like "BeginDrag" or "ItemDrag" event, so it's easy to put that code fragment there.
Maybe I will also find some use for them in the future! Lately, mostly work with web though...


Nikolay they also have a ton of web stuff even a diagram javascript control and a blazor diagram control! Also free under the community license, which you can use commercially as a small company.
Visio 2021 Professional

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 280 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1114KB.
Tokens: post-login.
Cache hits: 13: 0.00143s for 26,767 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]