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.

Visisthebest

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:
https://www.syncfusion.com/winforms-ui-controls/listview

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:
https://stackoverflow.com/questions/37492858/visio-vsto-drag-and-drop

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

Nikolay

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:
https://github.com/nbelyh/SampleVisioDragDropAddin

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.

Visisthebest

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

Nikolay


Visisthebest

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

Visisthebest

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:
https://www.syncfusion.com/winforms-ui-controls/listview

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:
https://www.syncfusion.com/products/communitylicense

(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

Nikolay

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...

Visisthebest

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