Nevron .NET Vision
Chart for .NET / User's Guide / Interactivity / Selection

In This Topic
    Selection
    In This Topic

    The selection object contains chart elements that the tools operate on. For example a the trackball drag tool searches for objects of type NChart in the selection. If such object is found the it can start to drag the chart and change its Rotation and Elevation.

    There are two ways to control the selection - programmatically or visually (performed by the user).

     Programmatically Controlling the Selection

    You can modify the current selection at runtime by calling the methods of the NSelection object. The following code clears the selection and adds the first chart in the charts collection:

    C#
    Copy Code
    chartControl.Controller.Selection.Clear();
    chartControl.Controller.Selection.Add(chartControl.Charts[0]);
    
    Visual Basic
    Copy Code
    chartControl.Controller.Selection.Clear()
    chartControl.Controller.Selection.Add(chartControl.Charts(0))
    

    Adding data points to the selection is slightly different:

    C#
    Copy Code
    chartControl.Controller.Selection.AddDataPoint(someSeries, 1);
    
    Visual Basic
    Copy Code
    chartControl.Controller.Selection.AddDataPoint(someSeries, 1)
    

    You can also perform queries in the selection in order to check whether it contains objects from certain type. The following code will check whether the selection contains a chart:

    C#
    Copy Code
    NSelection selection = chartControl.Controller.Selection;
    if (selection.ContainsObjectsOfType(typeof(NChart)))
    {
     ArrayList selectedChart = selection.GetSelectedObjectsOfType(typeof(NChart));
    
     // do something with selected charts
    }
    
    Visual Basic
    Copy Code
    Dim selection As NSelection = chartControl.Controller.Selection
    If selection.ContainsObjectsOfType(GetType(NChart)) Then
        Dim selectedChart As ArrayList = selection.GetSelectedObjectsOfType(GetType(NChart))
    
        ' do something with selected charts
    End If
    
     Visually Controlling the Selection

    You can also let the user the control the selected object by adding an instance of the NSelectorTool tool to the controller tools collection:

    C#
    Copy Code
    NSelectorTool selectorTool = new NSelectorTool();
    chartControl.Controller.Tools.Add(selectorTool);
    
    Visual Basic
    Copy Code
    Dim selectorTool As New NSelectorTool
    chartControl.Controller.Tools.Add(selectorTool)
    

    Now when the users clicks on the chart the selection will contain the object the mouse is currently over. You can also intercept the SelectionChanged event raised by the NSelectorTool when selection has changed.

    In practice you'll most likely use the NSelectorTool combined with some other tool - for example NTrackballTool allowing you to dynamically change the chart that the user rotates. Note that it is recommended that the NSelectorTool is the first tool in the Tools collection because this ensures that the rest of the tools operate on valid selection.

    See Also