Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: L.Krobot on March 07, 2015, 04:34:43 am
-
I'm developing various Add-Ins, and I would like to know how to enable the "Drag & Drop" of elements (or packages) from the Project Browser window into ListBox in my Add-In C# Windows Form.
thx.
-
I don't think you can. The only "drag-n-drop" feature currently implemented in the API is the EA_OnPreDropFromTree event, but I think that will only work if an element is dropped on an actual diagram, not if it is dropped on a add-in window.
But you never know...
If it doesn't work you can always send in a feature request (http://www.sparxsystems.com/support/feature_request.html)
Geert
-
Thanks,
as Geert said, there is no way to drop it directly on the form, but you must have open a diagram where you will try to drop your objects. It is not exactly what i wanted, but it works ...
You drag your object from the project browser to the diagram, and when you drop it, it will not drop on the diagram, but the name will appear in your ListBox (obviously, your add-in form must be activated and visible)...
here is how I did it:
1. first, I create the method:
public Boolean EA_OnPreDropFromTree( EA.Repository Repository, EA.EventProperties Info ) {
2. then, get the properties from Info:
// first property is: objectID
EA.EventProperty property = Info.Get( 0 );
string objectIdX = property.Value.Trim();
int objectId = Convert.ToInt32( objectIdX );
// second property is: objectType
property = Info.Get( 1 );
string objectTypeX = property.Value.Trim();
3. after this, get the objects, and add their names into ListBox:
switch ( objectTypeX )
{
case "4": // object type 4 = Element
EA.Element selectedElement = Repository.GetElementByID( objectId );
listBox1.Items.Add( selectedElement.Name );
break;
case "5": // object type 5 = Package
EA.Package selectedPackage = Repository.GetPackageByID( objectId );
listBox1.Items.Add( selectedPackage.Name );
break;
default:
break;
}
4. and on the end, return "false" in order to prevent dropping objects onto diagram:
return false;
full snippet:
public Boolean EA_OnPreDropFromTree( EA.Repository Repository, EA.EventProperties Info ) {
// first property is: objectID
EA.EventProperty property = Info.Get( 0 );
string objectIdX = property.Value.Trim();
int objectId = Convert.ToInt32( objectIdX );
// second property is: objectType
property = Info.Get( 1 );
string objectTypeX = property.Value.Trim();
switch ( objectTypeX )
{
case "4": // object type 4 = Element
EA.Element selectedElement = Repository.GetElementByID( objectId );
listBox1.Items.Add( selectedElement.Name );
break;
case "5": // object type 5 = Package
EA.Package selectedPackage = Repository.GetPackageByID( objectId );
listBox1.Items.Add( selectedPackage.Name );
break;
default:
break;
}
return false;
}
ljk