Intersoft ClientUI Documentation
DragDropEventData Class
Members 



Contains state information and event data associated with a drag drop event.
Object Model
DragDropEventData ClassDragDropBehavior Class
Syntax
Public Class DragDropEventData 
Dim instance As DragDropEventData
public class DragDropEventData 
public ref class DragDropEventData 
Remarks

When dealing with drag and drop, it is common to assign a data to be carried during the drag and drop operation. The drag-drop framework in ClientUI also provides this architecture to store the data in multiple formats.

Storing Data

To store the data, you can use the DragInit event or perform the drag-drop manually by using the provided API, then store the data when you call the API.

To learn how to enable drag and drop using API and storing the data using API, see How-to: Drag an UIElement using API.

To learn how to store the data at DragInit event, see How-to: Store DataObject at DragInit event.

Querying a Data Object for Available Formats

Because a single data object can contain an arbitrary number of data formats, data objects include facilities for retrieving a list of available data formats.

The following example code uses the GetFormats overload to get an array of strings denoting all data formats available in a data object.

GetFormats
Copy Code
    string sourceData = "Some string data to store...";
    byte[] unicodeText = Encoding.Unicode.GetBytes(sourceData);
    byte[] utf8Text = Encoding.UTF8.GetBytes(sourceData);

    string uniCodeFormat = "Unicode";
    string utf8DataFormat = "UTF-8";
            
    DragDropEventData dataObject = e.Data as DragDropEventData;
    dataObject.SetData(sourceData);
    dataObject.SetData(uniCodeFormat, unicodeText);
    dataObject.SetData(utf8DataFormat, utf8Text);

    // Get an array of strings, each string denoting a data format
    // that is available in the data object.  This overload of GetDataFormats
    // returns all available data formats, native and auto-convertible.
    string[] dataFormats = dataObject.GetFormats();

    // Get the number of data formats present in the data object, including both
    // auto-convertible and native data formats.
    int numberOfDataFormats = dataFormats.Length;

    // To enumerate the resulting array of data formats, and take some action when
    // a particular data format is found, use a code structure similar to the following.
    foreach (string dataFormat in dataFormats)
    {
        if (dataFormat == uniCodeFormat)
        {
            // Take some action if/when data in the Text data format is found.
            break;
        }
        else if (dataFormat == utf8DataFormat)
        {
            // Take some action if/when data in the string data format is found.
            break;
        }
    }

Retrieving Data from a Data Object

Retrieving data from a data object in a particular format simply involves calling one of the GetData methods and specifying the desired data format. One of the GetDataPresent methods can be used to check for the presence of a particular data format. GetData returns the data in a Object; depending on the data format, this object can be cast to a type-specific container.

The following example code uses the GetDataPresent(String) overload to first check if a specified data format is available (natively or by auto-convert). If the specified format is available, the example retrieves the data by using the GetData(String) method.

GetData
Copy Code
    string sourceData = "Some string data to store...";
    byte[] unicodeText = Encoding.Unicode.GetBytes(sourceData);
    byte[] utf8Text = Encoding.UTF8.GetBytes(sourceData);

    string uniCodeFormat = "Unicode";
    string utf8DataFormat = "UTF-8";
            
    DragDropEventData dataObject = e.Data as DragDropEventData;
    dataObject.SetData(sourceData);
    dataObject.SetData(uniCodeFormat, unicodeText);
    dataObject.SetData(utf8DataFormat, utf8Text);

    string desiredFormat = uniCodeFormat;
    byte[] data = null;

    // Use the GetDataPresent method to check for the presence of a desired data format.
    // This particular overload of GetDataPresent looks for both native and auto-convertible 
    // data formats.
    if (dataObject.GetDataPresent(desiredFormat))
    {
        // If the desired data format is present, use one of the GetData methods to retrieve the
        // data from the data object.
        data = dataObject.GetData(desiredFormat) as byte[];
    }
Inheritance Hierarchy

System.Object
   Intersoft.Client.UI.Controls.Interactivity.DragDropEventData

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DragDropEventData Members
Intersoft.Client.UI.Controls.Interactivity Namespace

Concepts

Drag-drop Framework Overview

Send Feedback