Share via


HierarchyInfo.OnSelected Method

Definition

Occurs when the object derived from HierarchyInfo is selected.

protected public:
 virtual bool OnSelected();
protected internal virtual bool OnSelected ();
abstract member OnSelected : unit -> bool
override this.OnSelected : unit -> bool
Protected Friend Overridable Function OnSelected () As Boolean

Returns

true if the HierarchyInfo object was successfully selected; otherwise, false. When this method is not overridden, returns true.

Examples

The following example implements the OnSelected method. The example adds a Select_tst command to the shortcut menu and specifies the display name "Select + Test". The example then calls the OnSelected method when the "Select + Test" command is clicked or when the node is selected.


/// GetTaskItems() is called every time the context menu is invoked.
public override System.Collections.ICollection GetTaskItems() {

    ArrayList items = new ArrayList();

    Image imgAsk = rLoadImg.loadImgs(SystemIcons.Asterisk, 16);
    Image imgErr = rLoadImg.loadImgs(SystemIcons.Error, 16);

    items.Add(new MethodTaskItem(
                "DisplayTime",       // Method Name
                "Show Time",        // Menu item Text
                "DemoCategory")    // Category
                );

    Person prs = new Person(66, "Joe", "Smith");
    MethodTaskItem mti_i = new MethodTaskItem(
                                    "InvTst",       // Method Name
                                    "Invoke Test",   // Menu item Text
                                    sDemoCat,       // Category
                                    "Tool Tip:SC",  // ToolTip non-functional
                                    imgAsk,          // Menu Icon
                                    prs);      // user data
    mti_i.CausesNavigation = false;
    traceMTI(mti_i);

    items.Add(mti_i);


    items.Add(new MethodTaskItem(
          "ShowCnt",       // Method Name
          "Show Count",   // Menu item Text
          sDemoCat,       // Category
          "Tool Tip:SC",  // ToolTip non-functional
          mti_i.Image)    // Menu Icon
          );

items.Add(new MethodTaskItem(
                   "Select_tst",
                   "Select + Test",
                   sDemoCat)
                   );
protected override bool OnSelected()
{

    TraceStateInfo();   // Send state info to Trace Listener
    if (_navSimp)
        return Navigate(typeof(DemoPage));

    return Connection.EndConfigurationManagement(typeof(DemoPage));
}

Remarks

Applications will typically use the OnSelected override to call the Navigate method. This method should return false when navigation is canceled. Arbitrary navigation between nodes is not always possible.

Applies to