Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Deleting of Nodes (Read 2796 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Deleting of Nodes
Nov 25th, 2010 at 8:31am
Print Post  
Hello!
I have the very strange problem. Some times (for example when I creates node by drag and drop) I can't delete node by Delete key. I have 2 event handlers for the Diagram object: NodeDeleting and KeyDown. When I press Delete I don't go to them. But when I press Esc I go to the KeyDown event handler. Why is it may be?
P.S.: when I create the node I use the NodeAdapter. Code is below:
Code
Select All
private void OnDiagram_NodeCreated(object sender, NodeEventArgs e)
        {
            if (e.Node is DiagramNodeAdapter)
            {
                DiagramNodeAdapter adapter = e.Node as DiagramNodeAdapter;
                TPDENode tpdeNode = new TPDENode();
                NodeType nType = (NodeType)adapter.Tag;
                if (nType == NodeType.SimpleProcess)
                    tpdeNode = new TechnologicalOperation();
                else if (nType == NodeType.ComplexProcess)
                    tpdeNode = new OperationGroupNode();
                else if (nType == NodeType.Bus)
                    tpdeNode = new BusNode();
                else if (nType == NodeType.Text)
                    tpdeNode = new CommentNode();
                else if (nType == NodeType.Reference)
                    tpdeNode = new ReferenceNode();
                else if (nType == NodeType.Filter)
                    tpdeNode = new FilterNode();
                else
                {
                    m_Diagram.Nodes.Remove(e.Node);
                    return;
                }
                m_Diagram.Nodes.Remove(e.Node);
                m_Diagram.Nodes.Add(tpdeNode);
            }
        }
 


Code
Select All
 private void OnDiagram_NodeDeleting(object sender, NodeValidationEventArgs e)
        {
            if (e.Node is TPDENode)
            {
                TPDENode node = e.Node as TPDENode;
                if (node is OperationGroupNode)
                {
                    String sMsg = "Deleting the complex process leads to permanently removing all included processes. Are you sure to delete the complex process?";
                    MessageBoxResult rslt = MessageBox.Show(sMsg, "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                    if (rslt == MessageBoxResult.No)
                        e.Cancel = true;
                    else m_bRemoveCnfr = true;
                }
                else if (node is InputNode || node is OutputNode || node is BeginNode ||
                    node is EndNode)
                    e.Cancel = true;
            }
        }
 


Code
Select All
        private void OnDiagram_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Escape:
                    m_Diagram.Selection.Clear();
                    break;
            }
        }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting of Nodes
Reply #1 - Nov 25th, 2010 at 8:45am
Print Post  
Hi,

Perhaps the keyboard focus changes to your hosted control. Try calling diagram.Focus() at the end of NodeCreated.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Deleting of Nodes
Reply #2 - Nov 25th, 2010 at 8:50am
Print Post  
No, it is not help me. And I see that when I click on the Node I can't delete it by Delete key. But when I draw selection by mouse and select the node I can delete selected (and active) node by delete key
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting of Nodes
Reply #3 - Nov 25th, 2010 at 8:54am
Print Post  
Then the focus shifts after NodeCreated is raised. Are you doing drag-and-drop from the NodeListView?
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Deleting of Nodes
Reply #4 - Nov 25th, 2010 at 9:05am
Print Post  
Yes, but the item of the NodeListView is the StackPanel which each child is consists of Image and TextBlock objects. And when I add into the NodeActivated event handler the string
e.Node.Selected = true;
all works. But the follwoing calls didn't get effect:
e.Node.Focus();
m_Diagram.Focus();
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Deleting of Nodes
Reply #5 - Nov 25th, 2010 at 11:49am
Print Post  
Indeed the NodeListView acquires the keyboard focus once the list item gets selected, but calling this from NodeCreated worked for me:

e.Node.Selected = true;
diagram.Focus();

There is NodeCreated raised after drag-and-drop creation, and not NodeActivated.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint