Diagram for .NET / User's Guide / WinForm Components / Selection

Selection

The selection is represented by an instance of the NSelection class, and can be obtained from the Selection property of the NView class.

C#
Copy Code
// obtain the selection
NSelection selection = view.Selection;
Visual Basic
Copy Code
' obtain the selection
Dim selection As NSelection = view.Selection
 Selection Mode

The selection can be configured to operate in three modes via its Mode property, which are:

  • Disabled - disables the selection feature 
  • Single - only a single node can be selected
  • Multiple - multiple nodes can be selected
 Getting the Selected Nodes

The currently selected nodes can be obtained from the Nodes property of the selection:

C#
Copy Code
// get the currently selected nodes
NNodeList selectedNodes = selection.Nodes;
Visual Basic
Copy Code
' get the currently selected nodes
Dim selectedNodes As NNodeList = selection.Nodes
Important: The returned list is a copy of the real selection content and inserting and removing nodes to/from it will not select/deselect the nodes.
 Selection Operations

The NSelection class provides a powerful set of methods, which can help you modify the selection. The most important ones are demonstrated in the following example:

C#
Copy Code
// make node1 the one and only selected node
selection.SingleSelect(node1);

// append node2 to the current selection
selection.MultiSelect(node2);

// toggle the selection state of the node3 (in this case this will select node3)
selection.Toggle(node3);

// toggle the selection state of the node3 (in this case this will deselect node3)
selection.Toggle(node3);

// deselect node1
selection.Deselect(node1);

// deselect all nodes (in this case only node2)
selection.DeselectAll();
Visual Basic
Copy Code
' make node1 the one and only selected node
selection.SingleSelect(node1)

' append node2 to the current selection
selection.MultiSelect(node2)

' toggle the selection state of the node3 (in this case this will select node3)
selection.Toggle(node3)

' toggle the selection state of the node3 (in this case this will deselect node3)
selection.Toggle(node3)

' deselect node1
selection.Deselect(node1)

' deselect all nodes (in this case only node2)
selection.DeselectAll()
 Selection anchor
The first or the last selected node is called selection anchor and can be used by different alignment and resize operations. Whether the first or the last selected node is the selection anchor is controlled by the AnchorMode property. The current selection anchor can be obtained from the AnchorNode property.

 Related Examples
Windows Forms:  Drawing View - Selection
See Also