DragAndDropEventArgs.DraggedNode

On version 19.2 getting error

DragAndDropEventArgs.DraggedNode' is obsolete: 'This property is deprecated


public void nodeDropped(DragAndDropEventArgs args)

    {

        diagram.BeginUpdate();

        Dictionary<string, object> value = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(args.Event.ToString());

        double x = Convert.ToDouble(value["screenX"]);

        double y = Convert.ToDouble(value["screenY"]);

        if (args.DraggedNode != null)

        {

            DiagramNode node = new DiagramNode()

            {

                Id = args.DraggedNode.ID,

                OffsetX = x - 415,

                OffsetY = y,

                Width = 100,

                Height = 100,

                Annotations = new ObservableCollection<DiagramNodeAnnotation>()

                {

                    new DiagramNodeAnnotation()

                    {

                        Content = args.DraggedNodeData.Text,

                        Offset = new NodeAnnotationOffset() { X = 0.75, Y = 0.5}

                    }

                }

            };

            diagram.Nodes.Add(node);

            diagram.EndUpdate();

        }

    }


3 Replies

GG Gowtham Gunashekar Syncfusion Team July 5, 2021 12:09 PM UTC

Hi John, 
 
On the further analysis of the shared details, we suspect that you have used treeview and you have dragged a node from treeview and dropped into diagram and added a diagram node dynamically at the place where you have dropped the treeview node. In treeview, the DraggedNode argument of DragAndDropEventArgs is deprecated. You can use DraggedNodeData argument to get tree node data.  
 
Code snippet: 
public void nodeDropped(DragAndDropEventArgs args) 
    { 
        diagram.BeginUpdate(); 
        Dictionary<string, object> value = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(args.Event.ToString()); 
        double x = Convert.ToDouble(value["screenX"]); 
        double y = Convert.ToDouble(value["screenY"]); 
        if (args.DraggedNodeData!= null) 
        { 
            DiagramNode node = new DiagramNode() 
            { 
                Id = args.DraggedNodeData.ID, 
                OffsetX = x - 415, 
                OffsetY = y, 
                Width = 100, 
                Height = 100, 
                Annotations = new ObservableCollection<DiagramNodeAnnotation>() 
                { 
                    new DiagramNodeAnnotation() 
                    { 
                        Content = args.DraggedNodeData.Text, 
                        Offset = new NodeAnnotationOffset() { X = 0.75, Y = 0.5} 
                    } 
                } 
            }; 
            diagram.Nodes.Add(node); 
            diagram.EndUpdate(); 
        } 
    } 
 
Please, let us know if you have any concerns.  
 
Regards, 
Gowtham 
 



JO John July 5, 2021 01:31 PM UTC

Hi Gowtham,

Thanks for this.  When I drop the item onto the grid I get the following error

System.Collections.Generic.KeyNotFoundException: The given key 'screenX' was not present in the dictionary


Also, once I drop the node I want to change it into an html element. I have tried the following, 

public void OnDrop(IBlazorDropEventArgs args)

        {

            args.Cancel = true;

            var NewNode = args.Element.Node;

            Diagram.Nodes.Add(new DiagramNode()

            {

                OffsetX = NewNode.OffsetX,

                OffsetY = NewNode.OffsetY,

                Width = NewNode.Width,

                Height = NewNode.Height,

                Shape = new DiagramShape()

                {

                    Type = Shapes.HTML,

                }


            });

        }


but that only works with

<DiagramEvents OnDrop="@OnDrop"></DiagramEvents>


In the SFDiagram I have

<DiagramTemplates>

<NodeTemplate>

 @{

<content><div>HTML here</div></content>

 }

 </NodeTemplate>

</DiagramTemplates>




AM Arunkumar Manoharan Syncfusion Team July 6, 2021 12:16 PM UTC

Hi John,

 
We have checked in our end with your code on the OnDrop event and we couldn’t be able to find any errors or exceptions. We attached the working sample with the OnDrop event in it if this sample does not resolve the issue, we request you to replicate it in this sample so that we can be able to serve you better. 
 
 
Regards,
Arun
 


Loader.
Up arrow icon