DragDropData Class



Class that implements the special clipboard data formats used during copy/paste and drag/drop. This is a shallow class on top of the native DataObject.


When to Use This Class

The typical use for this class is to get the data associated with drag/copy operations from the clipboard, and more specifically, the specially formatted pathnames and persistence string.



How to Use This Class

Add a reference to the OSISoft.PISDK.Controls.MDBTreeNet Control and create this class. Use the appropriate  properties and methods to retrieve the needed data. For specific usage instructions, please view the examples below.



Clipboard formats

The object implements two clipboard formats: PATHNAMESCLIPBOARDFORMAT and PERSISTENCECLIPBOARDFORMAT. The DragDropData automatically registers these formats and provides properties that return the registered format identifier. These formats are defined in a separate definition class that only contains static constants as follows:

DragDropFormats.PATHNAMES - This constant can be used in conjunction with DragDropDta methods when dealing with path names.

DragDropFormats.PERSISTENCE - This constant can be used in conjunction with DragDropDta methods when dealing with persistence strings.




    Assembly: OSIsoft.PISDK.Controls.DragDropData (in OSIsoft.PISDK.Controls.MDBTreeNet.dll).






This example shows how to use the DragDropData object when data is being dragged from the MDBTreeNet control and dropped onto a standard textbox control. We also demonstrate how to access persistence and pathname data directly from clipboard when pasting data that originates from MDBTreeNet control.


1. Create a Windows Form application for MDBTreeNet user control (see "how to" instructions)

2. Add three (3) standard textboxes and make them fairly large. Change the "Multiline" property to TRUE for all three textboxes.

3. In the Design View, right-click on the first text box (textbox1) and select properties. Select the "Events" tab and double-click on the "KeyPressed" event.

4. Replace the empty method definition by the following code:


/// <summary>

/// This method is called when the user presses a key on the first textbox (textBox1).

/// If the key sequence is CTRL + V (paste), we will fill the two other textboxes with

/// clipboard data. The third box will show the Persistence string of the copied module

/// while the second box shows the full pathname. All this naturally assumes that the

/// MDBTreeNet was used to set the data in the first place (either Copy or drag start).

/// Note the we don't cancel the event because we want the "textBox1" do the default paste,

/// i.e. show the normal text data (which is the name of the module).

/// </summary>

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

/// <param name="e">KeyPressed arguments - contains the key code</param>

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)


    if ((int)e.KeyChar == 22)

    { // not very intuitive way to catch CTRL + V

        IDataObject ddData = Clipboard.GetDataObject(); // get data from clipboard

        if (ddData.GetDataPresent(DragDropFormats.PERSISTENCE))

        { // persistence string is present

            textBox3.Text = ddData.GetData(DragDropFormats.PERSISTENCE).ToString(); // show the persistence string


        if (ddData.GetDataPresent(DragDropFormats.PATHNAMES))

        { // pathname string is present

            textBox2.Text = ddData.GetData(DragDropFormats.PATHNAMES).ToString(); // show the pathname string





5. Compile and run the application. Open the tree-view nodes so that at least one PIModule node is visible, select/click the node

and press CTRL + C (copy).

6. Select/highlight the textbox1 and press CTRL +V (paste) and observe the contents of each of the textboxes.


7. Activate the design view and select properties for the textbox1. Select the Properties tab and change AllowDrop property

from false to true. Select the Events tab and double-click on the followowing events: DragEnter and DragDrop.

8. In the code view, replace the two empty event handler methods with the following code:


/// <summary>

/// This method is called when drag/drop operation enters the textbox. We will change

/// the drag image to match "COPY" if the desired formats are present in the passed DataObject

/// </summary>

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

/// <param name="e">Event arguments containing the data object</param>

private void textBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)


    if (e.Data.GetDataPresent(DragDropFormats.PERSISTENCE))

        e.Effect = DragDropEffects.Copy;    // at leas one valid/special format present -> change image to COPY


        e.Effect = DragDropEffects.None;    // data not valid for this operation


/// <summary>

/// This method is called when the user drops data from MDBTreeNet on the textbox.

/// We will use the DataObject that is passed with event arguments to access the

/// data but otherwise the operations are equivalent to the "paste" example.

/// </summary>

/// <param name="sender">Event source object</param>

/// <param name="e">Event arguments containing the actual DataObject that the MDBTreeNet

/// created at DragStart</param>

private void textBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)


    if (e.Data.GetDataPresent(DragDropFormats.PATHNAMES))

        textBox2.Text = e.Data.GetData(DragDropFormats.PATHNAMES).ToString();

    if (e.Data.GetDataPresent(DragDropFormats.PERSISTENCE))

        textBox3.Text = e.Data.GetData(DragDropFormats.PERSISTENCE).ToString();



9. Compile and run the application. Open/expand the tree-view and drag a node onto textbox1. The drag image should

change to "Copy" image as soon as the cursor enters the textbox. Drop the data and see that the data matches to that

of the copy/paste operation.

Enabling Operational Intelligence