Diagram / Diagram DOM / Drawings / Pages / Page Selection
In This Topic
    Page Selection
    In This Topic

    NOV Diagram for .NET lets you easily select one, more or all diagram items in a drawing page. To select/deselect shapes use the page's Selection property.

     Selection

    To get all currently selected diagram items, use the SelectedItems property of the page's selection:

    Get all currently selected diagram items in the page
    Copy Code
    NList<NDiagramItem> selectedItems = page.Selection.SelectedItems;
    

    To check if any shapes (NShape instances) are selected, use the HasShapes property of the page's selection - it checks whether at least one of the currently selected diagram items is a shape (NShape):

    Check if any shapes are selected
    Copy Code
    if (page.Selection.HasShapes)
    {
        // Your code here
    }
    
     Selecting Shapes

    The page's Selection object provides the following methods for selecting shapes and other diagram items.

    • SingleSelect - makes the specified item or list of items the only selected items.
      Make a shape the only selected item
      Copy Code
      page.Selection.SingleSelect(myShape);
      
    • MultiSelect - appends the given item or list of items to the current page selection without removing the currently selected items.
    • ToggleSelect - toggles the selection of the given item or list of items, i.e. if the items were not selected, this method selects them and vice versa.
    • SelectAll - selects all 1D, all 2D or all shapes in the page based on the specified parameter. The following code shows how to select all 2D shapes in a page:
      Select all 2D shapes
      Copy Code
      NPage page = drawingView.ActivePage;
      page.Selection.SelectAll(ENSelectAllFilter.Shapes2D);
      
     Deselecting Shapes

    To deselect shapes, use the following method of the shape:

    • Deselect - deselects one or more diagram items.
    • DeselectAll - deselects all diagram items.
     Other Selection Properties and Methods

    The page selection provides the following properties:

    • Mode - defines the selection mode. Can be Single or Multiple.
    • SelectedCount - gets the number of currently selected items.
    • SelectedItems - gets the list of currently selected items.
    • HasShapes - indicates whether the page selections contains any shapes.
    • AlignmentAnhor - gets the node towards which alignment commands are executed.
    • AlignmentAnchorMode - defines the alignment anchor mode. By default the last selected shape is the alignment anchor.
    • FormatAnchor - gets the node towards which formatting commands are executed.
    • FormatAnchorMode - defines the formatting anchor mode. By default the last selected shape is the format anchor.
    • BatchDelete - gets a batch, whose Delete method can be used to delete all currently selected shapes.
      C#
      Copy Code
      if (page.Selection.BatchDelete.CanDelete())
      {
          page.Selection.BatchDelete.Delete();
      }
      
    • BatchGroup - gets a batch, whose Group method can be used to group all currently selected shapes.
      C#
      Copy Code
      if (page.Selection.BatchGroup.CanGroup())
      {
          NGroup group;
          page.Selection.BatchGroup.Group(page, out group);
      }
      

    For more information about batches open the Diagram Batches topic.

    The page selection also provides the following methods:

    • IsSelected - check whether the given diagram item is selected.
    • GetBounds - gets the selection bounds in page coordinates.

     

    See Also