OSIsoft.SDK.Controls.PIAcrhiveEditor Tutorial

In this example we illustrate the use of the PIArchiveEditor control by adding it to a Visual Studio.Net project. The example is very simple, since the the editor is quite independent. The example demonstrates how to subscribe to error events and how retrieve current data and related information from the control.

  1. STEP 1. Set up the project

Start Visual Studio and select a new "Visual C# - Windows Application" project. Follow the instructions described earlier in this chapter on how to add the necessary references and the controls to the project.

You don't need to add any references to the project, as soon as you insert the control into the form, the system will automatically add them for you.

  1. STEP 2. Insert controls

From the toolbox, select and place the following controls onto the form:

See the screen capture later in this chapter for placement and sizing details.

  1. STEP 3. Set control properties

Change the Text property of the button to "Get Info".

  1. STEP 4. Add/Select event handlers

Switch to design view and double-click on an empty spot of the form. Double-click on the button also. The system will create the handler prototypes for you.

  1. STEP 5. Add initialization code

Add a namespace usage definition in the "using" section:


using OSIsoft.SDK.Controls;

  1. STEP 6. Add event handler code

Replace the event handler stubs that were created by the Designer with the following:



/// <summary>

/// Setup the Archive editor.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void piArchiveEditor1_Load(object sender, System.EventArgs e)


    piArchiveEditor1.setTimeRange("*-5h", "*-10m"); // set initial timerange

    // set defaults...demonstration only

    piArchiveEditor1.AllowValueEdit = true; // allow edits

    piArchiveEditor1.AllowAnnotations = true; // allow annotation edits

    piArchiveEditor1.UseSrvPickList = true; // use picklist instead of defined list

    // add error event handler

    piArchiveEditor1.errorEvent += new ErrEventHandler(archEditErrHandler);

    // commented out - example of defined serverlist

    // piArchiveEditor1.UseSrvPickList = false; // use defined servers

    // piArchiveEditor1.ServerList = new String[] {"localhost", "otherserver"}; // set servers



Add the error event handler code:


/// <summary>

/// Archive editor error event handler. Show messagebox for each error

/// </summary>

/// <param name="sender">The editor</param>

/// <param name="e">Error event args</param>

private void archEditErrHandler(object sender, ErrEventArgs e)


    MessageBox.Show(this, "ERROR: " + e.message + " from " + e.origin, "PIAcrhiveEditor error");




/// <summary>

/// Get Info button handler. Retrieve various properties and show in MessageBox

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void button1_Click(object sender, System.EventArgs e)


    string msg = "Tagname=";

    if (piArchiveEditor1.PITag is PISDK.PIPoint)

        msg += ((PISDK.PIPoint)piArchiveEditor1.PITag).Name; // get tagname from point

    else if (piArchiveEditor1.PITag is string)

        msg += (string)piArchiveEditor1.PITag;     // it is string..

    msg += " Even Count=" + piArchiveEditor1.EventList.eventCount.ToString()+ Environment.NewLine;

    if (piArchiveEditor1.CurrentValue != null)

        msg += "Selected value=" + piArchiveEditor1.CurrentValue.Value.ToString()+ Environment.NewLine;


        msg += "Selected value is undefined" + Environment.NewLine;

    msg += "StartTime=" + piArchiveEditor1.StartTime.LocalDate.ToString() +

            "; EndTime=" + piArchiveEditor1.EndTime.LocalDate.ToString();

    MessageBox.Show(this, msg, "PIArchiveEditor data");



  1. STEP 7. Test the control

Save the project and run it. The editor should come up empty and the time range should match the test setup. Select or specify a valid tag and press the "Get Events" button to populate the datagrid with events. Press the "Get Info" button and verify that the information is correct.

This is how the completed form should appear:


Enabling Operational Intelligence