Share via


MethodTaskItem.UserData Property

Definition

Gets the user data for the task item.

public:
 property System::Object ^ UserData { System::Object ^ get(); };
public object UserData { get; }
member this.UserData : obj
Public ReadOnly Property UserData As Object

Property Value

The user data for the MethodTaskItem object.

Examples

The following example creates a MethodTaskItem object that contains a Person object. When you click the Invoke Test menu item, the trace listener displays the following output.

InvTst : person age: 66

First name "Joe"

Last name Smith"

internal class DemoHierProvidr : HierarchyProvider
{

    private DemoHierarchyInfo _info;
    public DemoHierProvidr(IServiceProvider serviceProvider)
        : base(serviceProvider)
    {
    }

// DemoHierarchyInfo.InvTst()
//
public int InvTst(Person p)
{
    Trace.WriteLine(" InvTst : person age: " + p._age.ToString()
    + "\n First name \"" + p._fName
    + "\"\n Last name " + p._LstName + "\"");

    return SH._pCnt;
}

private sealed class HierarchyDemoInfoTaskList : TaskList
{
    private DemoHierarchyInfo _owner;
    private bool _dirtyState = false;
    Person _curPerson = new Person(23, "Albert", "Smith");

    public HierarchyDemoInfoTaskList(DemoHierarchyInfo owner) {
        _owner = owner;
    }

    public void Delete()
    {
        _owner.Delete();
    }

    public override bool IsDirty
    {
        get
        {
            return _dirtyState;
        }
    }

    /// GetTaskItems() is called every time the context menu is invoked
    /// For better perf, move ArrayList items = new ArrayList(); to
    /// to the class (as _items) and only initialize once
    /// 

    /// 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);

// method DemoHierarchyInfo.HierarchyDemoInfoTaskList.InvTst()
public void InvTst(object obj)
{
    // Call parents InvTst (DemoHierarchyInfo.InvTst )
    //
    _owner.InvTst((Person)obj);
    UpdateCurPers();
    _owner.flush();
}
// DemoHierarchyInfo.InvTst()
//
public int InvTst(Person p)
{
    Trace.WriteLine(" InvTst : person age: " + p._age.ToString()
    + "\n First name \"" + p._fName
    + "\"\n Last name " + p._LstName + "\"");

    return SH._pCnt;
}

Remarks

To initialize the user data, call the MethodTaskItem constructor.

Applies to