James Dzierwa

Hi all,

I recently wrote some code to pull database objects from Server Explorer into a DSL Tools project in VS.NET 2005 and ran into a strange issue.

If I have a table Customers with two fields, CustomerID and CustomerName in Server Explorer, and I drag-and-drop just the Customers table over onto my designer surface, the DSRef tree consists of only the DataSource and Customers nodes; the field nodes of the Customers table aren't there.

If I expand the table in Server Explorer and drag-and-drop the CustomerID node onto my designer surface, then the DSRef tree contains the DataSource, Customers table, and CustomerID field nodes.

Here is the relevant code for grabbing the DSRef input:

Code Snippet

// inside my Microsoft.VisualStudio.Modeling.Diagrams.Diagram class.

protected override void OnAssociated(DiagramAssociationEventArgs e)

{

base.OnAssociated(e);

if (e.DiagramView == null || e.DiagramView.DiagramClientView == null)

return;

Control ctrl = e.DiagramView.DiagramClientView;

ctrl.AllowDrop = true;

ctrl.DragOver += new DragEventHandler(OnDragOver);

ctrl.DragDrop += new DragEventHandler(OnDragDrop);

}

private void OnDragOver(object sender, DragEventArgs e)

{

if (e.Data.GetDataPresent("CF_DSREF"))

{

e.Effect = DragDropEffects.Copy;

}

}

private void OnDragDrop(object sender, DragEventArgs e)

{

if (e.Data.GetDataPresent("CF_DSREF"))

{

try

{

using (DSRefInput input = new DSRefInput(e.Data.GetData("CF_DSREF") as Stream))

{

// create DSL elements from data.

}

}

}

}

class DSRefInput

{

private IDSRefConsumer _consumer;

public DSRefInput(Stream data)

{

_consumer = null;

IntPtr p = IntPtr.Zero;

IntPtr stm = IntPtr.Zero;

IntPtr ntv = IntPtr.Zero;

try

{

byte[] buf = new byte[data.Length];

data.Seek(0, SeekOrigin.Begin);

data.Read(buf, 0, buf.Length);

ntv = Marshal.AllocHGlobal(buf.Length);

Marshal.Copy(buf, 0, ntv, buf.Length);

int result = CreateStreamOnHGlobal(ntv, false, ref stm);

Marshal.ThrowExceptionForHR(result);

result = OleLoadFromStream(stm, typeof(IDSRefConsumer).GUID.ToByteArray(), ref p);

Marshal.ThrowExceptionForHR(result);

_consumer = Marshal.GetObjectForIUnknown(p) as IDSRefConsumer;

}

finally

{

Marshal.Release(p);

Marshal.Release(stm);

Marshal.Release(ntv);

}

}

}

I've iterated through every node in the input tree when dragging-and-dropping a table and it definitely does not include field nodes.

Is there a way to get Server Explorer to send over a particular tree node and its children when dragging-and-dropping it onto a custom designer pane

Thank you in advance,

James



Re: Visual Studio Extensibility Dragging-and-Dropping Node Trees from Server Explorer

TjMulder

I am struggling with the same thing currently. I also would be very interested in the answer