Facing problem on External Object Drag Event

Hello to all

I am a new GoProgrammer. I make an application as shown in picture below.when I drag a network element from left pane to right pane there are fillowing error show.
Can you please suggest where i am wrong.
I attched the code where this error shows.
Please suggest me It is Very urgent
private void myView_ExternalObjectsDropped(object sender, GoInputEventArgs e) {

SqlConnection conn = new SqlConnection(strCon);
conn.Open();

try
{
GraphNode ParentNode = myView.PickObject(true, false, myView.LastInput.DocPoint, true) as GraphNode;
string strQuery = "INSERT INTO provision(provision_name,capacity_id,status_type_id,update_dt,insert_dt,last_user) "

  • “values(’” + ParentNode.Text.Trim() + “’,” + ParentNode.ImageID + “,1,’” + DateTime.Now + “’,’” + DateTime.Now + “’,‘cadebill’)”;
    SqlCommand Comm = new SqlCommand(strQuery, conn);
    int result = Comm.ExecuteNonQuery();
    RefreshProvisionTree();
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    finally
    {
    }

}

You should be able to debug this with Visual Studio. My guess is that your “ParentNode” variable is null.

That’s because the user didn’t perform the drop onto a node. Why? At least two possibilities:

(1) the drop happened where there wasn’t any object in the document, or
(2) the drop happened on a part of the node, not on the whole node.

You need to handle both cases. I can’t tell you what to do for (1), but for (2), I suggest you do:

GoObject obj = myView.PickObject(true, false, e.DocPoint, true);

if (obj == null) {

... // didn't drop on top of a document object

} else {

GraphNode node = obj.ParentNode as GraphNode;

if (node != null) {

... // dropped onto (part of) a GraphNode

} else {

... // dropped onto a link?

}

}

Thanx Walter for quick reply.