Class

# DragItem

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to transfer data being dragged by the user via drag and drop.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                | Type                                                   | Read-Only | Shared |
|-------------------------------------|--------------------------------------------------------|-----------|--------|
| `Destination<dragitem.destination>` | `Object</api/data_types/additional_types/object>`      | ✓         |        |
| `DragPicture<dragitem.dragpicture>` | `Picture</api/graphics/picture>`                       |           |        |
| `DropHeight<dragitem.dropheight>`   | `Integer</api/data_types/integer>`                     |           |        |
| `DropLeft<dragitem.dropleft>`       | `Integer</api/data_types/integer>`                     |           |        |
| `DropTop<dragitem.droptop>`         | `Integer</api/data_types/integer>`                     |           |        |
| `DropWidth<dragitem.dropwidth>`     | `Integer</api/data_types/integer>`                     |           |        |
| `FolderItem<dragitem.folderitem>`   | `FolderItem</api/files/folderitem>`                    |           |        |
| `Handle<dragitem.handle>`           | `Integer</api/data_types/integer>`                     | ✓         |        |
| `MouseCursor<dragitem.mousecursor>` | `MouseCursor</api/user_interface/desktop/mousecursor>` |           |        |
| `Picture<dragitem.picture>`         | `Picture</api/graphics/picture>`                       |           |        |
| `Text<dragitem.text>`               | `String</api/data_types/string>`                       |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                                | Parameters                                                                                                                                                                                                                                                                                                                       | Returns                            | Shared |
|-----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `AddItem<dragitem.additem>`                         | left As `Integer</api/data_types/integer>`, top As `Integer</api/data_types/integer>`, width As `Integer</api/data_types/integer>`, height As `Integer</api/data_types/integer>`                                                                                                                                                 |                                    |        |
| `Constructor<dragitem.constructor0>`                | ctl As `DesktopUIControl</api/user_interface/desktop/desktopuicontrol>`, x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`, width As `Integer</api/data_types/integer>`, height As `Integer</api/data_types/integer>`, dragPicture As `Picture</api/graphics/picture>` = `Nil</api/language/nil>` |                                    |        |
| `Constructor<dragitem.constructor1>`                | w As `DesktopWindow</api/user_interface/desktop/desktopwindow>`, x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`, width As `Integer</api/data_types/integer>`, height As `Integer</api/data_types/integer>`, dragPicture As `Picture</api/graphics/picture>` = `Nil</api/language/nil>`         |                                    |        |
| `Drag<dragitem.drag>`                               |                                                                                                                                                                                                                                                                                                                                  |                                    |        |
| `FolderItemAvailable<dragitem.folderitemavailable>` |                                                                                                                                                                                                                                                                                                                                  | `Boolean</api/data_types/boolean>` |        |
| `MoveFirst<dragitem.movefirst>`                     |                                                                                                                                                                                                                                                                                                                                  |                                    |        |
| `NextItem<dragitem.nextitem>`                       |                                                                                                                                                                                                                                                                                                                                  | `Boolean</api/data_types/boolean>` |        |
| `PictureAvailable<dragitem.pictureavailable>`       |                                                                                                                                                                                                                                                                                                                                  | `Boolean</api/data_types/boolean>` |        |
| `PrivateRawData<dragitem.privaterawdata>`           | macType As `String</api/data_types/string>`                                                                                                                                                                                                                                                                                      | `String</api/data_types/string>`   |        |
|                                                     | macType As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                                                                                                                                                          |                                    |        |
| `RawData<dragitem.rawdata>`                         | dataType As `String</api/data_types/string>`                                                                                                                                                                                                                                                                                     | `String</api/data_types/string>`   |        |
|                                                     | dataType As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                                                                                                                                                         |                                    |        |
| `RawDataAvailable<dragitem.rawdataavailable>`       | macType As `String</api/data_types/string>`                                                                                                                                                                                                                                                                                      | `Boolean</api/data_types/boolean>` |        |
| `TextAvailable<dragitem.textavailable>`             |                                                                                                                                                                                                                                                                                                                                  | `Boolean</api/data_types/boolean>` |        |

## Enumerations

<div id="dragitem.types">

<div class="rst-class">

forsearch

</div>

</div>

DragItem.Types

### Types

> Specifies the type of drag the user is making.
>
> | Enumeration | Description            |
> |-------------|------------------------|
> | Default     | Default action.        |
> | Copy        | Copy the dragged item. |
> | Move        | Move the dragged item. |
> | Link        | Link the dragged item. |
>
> This property is read-only and set at runtime.

## Property descriptions

<div id="dragitem.destination">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Destination

**Destination** As `Object</api/data_types/additional_types/object>`

> The location of the dropped item when you drop it to the desktop or onto an application. The <span class="title-ref">DragItem</span> must contain some content that the Finder accepts.
>
> This property is read-only.
>
> Since *Destination* is of type `Object</api/data_types/additional_types/object>`, it potentially can return any type of Xojo object. Currently, *Destination* is set up to work only with the macOS Finder and will only return a `FolderItem</api/files/folderitem>`. To ensure that your application is compatible with future versions, check the type of object it returns with `IsA</api/language/operators/comparison/isa>` before recasting it to a `FolderItem</api/files/folderitem>`.
>
> On macOS to determine the destination, pass "public.file-url" to the `RawData<dragitem.rawdata>` method. When doing so, assigning a non-empty string to `RawData<dragitem.rawdata>` will write that data to the file created at the destination.
>
> On Windows and Linux, dragging items to the Desktop is not supported; therefore this property does not work on those platforms.
>
> This code uses the Destination property to report the NativePath of a folder that is created by dragging a label from a window to the Finder:
>
> ``` xojo
> Var f As FolderItem = SpecialFolder.Temporary.Child("test" + Format(d.TotalSeconds, "#"))
>
> If f <> Nil Then
>
>   Var tos As TextOutputStream
>
>   tos = TextOutputStream.Create(f)
>   tos.Write("Howdy! Created by DragToFinder example.")
>   tos.Close
>
>   Var di As New DragItem(Self, 0, 0, 100, 100)
>
>   di.FolderItem = f 
>   di.Drag
>
>   If di.Destination <> Nil Then
>
>     If di.Destination IsA FolderItem Then
>       MessageBox(FolderItem(di.Destination).NativePath)
>     End If
>
>   End If
>
> Else
>   MessageBox("Unable to get FolderItem for temporary file.")
> End If
> ```

<div id="dragitem.dragpicture">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.DragPicture

**DragPicture** As `Picture</api/graphics/picture>`

> If you assign an image to this property, the picture will be used for the drag instead of the default rectangle. The image will be placed at the top left of the rectangle passed into the <span class="title-ref">DragItem</span> constructor.
>
> It is only possible to change the DragPicture *before* calling `Drag<dragitem.drag>`, any attempt to do so after that point will fail.
>
> This code sets the DragPicture property just after creating the new <span class="title-ref">DragItem</span>.
>
> In an ImageViewer control, put this code in the MouseDown event:
>
> ``` xojo
> Return True
> ```
>
> You can then set up the drag in the MouseDrag event of the ImageViewer:
>
> ``` xojo
> Var d As New DragItem(Self, X, Y, Me.Width, Me.Height)
>
> d.DragPicture = MyPicture ' a picture/image added to the project
> d.Picture = Me.Image ' From the ImageViewer control
>
> d.Drag ' Allow the drag
> ```

<div id="dragitem.dropheight">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.DropHeight

**DropHeight** As `Integer</api/data_types/integer>`

> Height of the object being dropped.
>
> The following code displays the values of the DropWidth and DropHeight properties after the drag. The code is in the DropObject event.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable Then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
>
> Label1.Text = obj.DropWidth.ToString
> Label2.Text = obj.DropHeight.ToString
> ```

<div id="dragitem.dropleft">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.DropLeft

**DropLeft** As `Integer</api/data_types/integer>`

> Distance from the left side of the control where the object was dropped.
>
> The following code displays the values of the DropLeft and DropTop properties after the drag. The code is in the DropObject event.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable Then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
>
> Label1.Text = obj.DropLeft.ToString
> Label2.Text = obj.DropTop.ToString
> ```

<div id="dragitem.droptop">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.DropTop

**DropTop** As `Integer</api/data_types/integer>`

> Distance from the top of the control where the object was dropped.
>
> The following code displays the values of the DropLeft and DropTop properties after the drag. The code is in the DropObject event.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable Then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
>
> Label1.Text = obj.DropLeft.ToString
> Label2.Text = obj.DropTop.ToString
> ```

<div id="dragitem.dropwidth">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.DropWidth

**DropWidth** As `Integer</api/data_types/integer>`

> Width of the object being dropped.
>
> The following code displays the values of the DropWidth and DropHeight properties after the drag. The code is in the DropObject event.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable Then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
>
> Label1.Text = obj.DropWidth.ToString
> Label2.Text = obj.DropHeight.ToString
> ```

<div id="dragitem.folderitem">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.FolderItem

**FolderItem** As `FolderItem</api/files/folderitem>`

> The `FolderItem</api/files/folderitem>` being dragged.
>
> The following DropObject event specifies the passed `FolderItem</api/files/folderitem>` as the object to be dropped.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable Then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
> ```

<div id="dragitem.handle">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Handle

**Handle** As `Integer</api/data_types/integer>`

> Returns the macOS handle to the <span class="title-ref">DragItem</span>. Handle returns 0 on Windows and Linux.
>
> This property is read-only.
>
> The following gets a handle to the <span class="title-ref">DragItem</span>.
>
> ``` xojo
> Var d As New DragItem(Self, X, Y, Me.Width, Me.Height)
> Var i As Integer = d.Handle
> ```

<div id="dragitem.mousecursor">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.MouseCursor

**MouseCursor** As `MouseCursor</api/user_interface/desktop/mousecursor>`

> The cursor to be displayed during the drag.
>
> The following code displays a custom cursor for the drag. It is in the MouseDown event of the `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`.
>
> ``` xojo
> Var d As New DragItem(Self, X, Y, Me.Width, Me.Height)
>
> d.DragPicture = MyPicture
> d.MouseCursor = System.Cursors.HandOpen
> d.Picture = Me.Image
>
> d.Drag ' Allow the drag
> ```

<div id="dragitem.picture">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Picture

**Picture** As `Picture</api/graphics/picture>`

> The Picture being dragged.
>
> The following code is in the DropObject event handler of an `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`. It assigns the dragged picture to the Image property of the `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
> ```

<div id="dragitem.text">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Text

**Text** As `String</api/data_types/string>`

> The text being dragged.
>
> The following DropObject event handler of a `ListBox</api/user_interface/desktop/desktoplistbox>` determines whether the dragged item has text; if it does, it creates a new row and assigns the dragged item's text property to the new row.
>
> ``` xojo
> If obj.TextAvailable Then
>   Me.AddRow(obj.Text)
> End If
> ```

## Method descriptions

<div id="dragitem.additem">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.AddItem

**AddItem**(left As `Integer</api/data_types/integer>`, top As `Integer</api/data_types/integer>`, width As `Integer</api/data_types/integer>`, height As `Integer</api/data_types/integer>`)

> Adds an item to the drag object. The parameters specify the drag rectangle to be displayed.
>
> This allows you do add additional items to the drag. After calling AddItem, you assign new values to all the <span class="title-ref">DragItem</span> properties for the newly added item. When the item is dropped, the NextItem method can be called to iterate through all the items in the <span class="title-ref">DragItem</span>.
>
> Add two pictures to a \`DragItem\`:
>
> ``` xojo
> Var d As New DragItem(Self, X, Y, Me.Width, Me.Height)
>
> d.DragPicture = MyDragPic
> d.MouseCursor = System.Cursors.HandOpen
> d.Picture = MyFirstPic
> d.AddItem(0, 0, Me.Width, Me.Height)
> d.Picture = MySecondPic
>
> d.Drag ' Allow the drag
> ```

<div id="dragitem.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Constructor

**Constructor**(ctl As `DesktopUIControl</api/user_interface/desktop/desktopuicontrol>`, x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`, width As `Integer</api/data_types/integer>`, height As `Integer</api/data_types/integer>`, dragPicture As `Picture</api/graphics/picture>` = `Nil</api/language/nil>`)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates a new <span class="title-ref">DragItem</span>. The parameter *ctl* is the `DesktopUIControl</api/user_interface/desktop/desktopuicontrol>` that the drag originates from. The parameters *x* and *y* are the coordinates relative to this control. The parameters *width* and *height* are the size/bounds of the drag rectangle. If the optional *dragPicture* parameter is passed, it will be used instead of the default rectangle to indicate the size and shape of the dragged item during the drag.

<div id="dragitem.constructor1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Constructor

**Constructor**(w As `DesktopWindow</api/user_interface/desktop/desktopwindow>`, x As `Integer</api/data_types/integer>`, y As `Integer</api/data_types/integer>`, width As `Integer</api/data_types/integer>`, height As `Integer</api/data_types/integer>`, dragPicture As `Picture</api/graphics/picture>` = `Nil</api/language/nil>`)

> Creates a new <span class="title-ref">DragItem</span>. The parameter *w* is the window that the drag originates from. The parameters *x* and *y* are the coordinates relative to this window. The parameters *width* and *height* are the size/bounds of the drag rectangle. If the optional *dragPicture* parameter is passed, it will be used instead of the default rectangle to indicate the size and shape of the dragged item during the drag.
>
> The following code is from the example project "Custom Drag" in the Examples folder. The main window consists of a `DesktopLabel</api/user_interface/desktop/desktoplabel>` control and a `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`. The user can drag the text in the `DesktopLabel</api/user_interface/desktop/desktoplabel>` into the `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`. This is not possible by default but the ability to drag the text is enabled by the code in the MouseDown event of the `DesktopLabel</api/user_interface/desktop/desktoplabel>`. It is:
>
> ``` xojo
> Var d As New DragItem(Self, Me.Left, Me.Top, Me.Width, Me.Height)
>
> d.Text = Me.Text
>
> d.Drag ' Allow the drag
> ```
>
> This example drags a picture. It uses the optional DragPicture property in the constructor.
>
> ``` xojo
> Var d As New DragItem(Self, X, Y, Me.Width, Me.Height, MyPicture)
>
> d.MouseCursor = System.Cursors.HandOpen
> d.AddItem(0, 0, Me.Width, Me.Height)
> d.Picture = Me.Image
>
> d.Drag ' Allow the drag
> ```

<div id="dragitem.drag">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.Drag

**Drag**

> Allows the drag to take place. Note that it is only possible to change the image before calling Drag, any attempt to do so after that point will fail.
>
> This code drags the picture that is assigned to the Image property of an `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>` to another `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`. In the MouseDown event of the first `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`, Drag is used to allow the drag.
>
> ``` xojo
> Var d As New DragItem(Self, X, Y, Me.Width, Me.Height)
>
> d.DragPicture = Keaton534
> d.MouseCursor = System.Cursors.HandOpen
> d.Picture = Me.Image
>
> d.Drag ' Allow the drag
> ```
>
> In the second ImageViewer, put this code in its `Opening<desktopuicontrol.opening>` event to allow the picture drop:
>
> ``` xojo
> Me.AcceptPictureDrop
> ```

<div id="dragitem.folderitemavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.FolderItemAvailable

**FolderItemAvailable** As `Boolean</api/data_types/boolean>`

> If `True</api/language/true>`, the FolderItem property contains a `FolderItem</api/files/folderitem>`.

<div id="dragitem.movefirst">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.MoveFirst

**MoveFirst**

> If the <span class="title-ref">DragItem</span> contains multiple items, this method makes the first item the active item.
>
> The *active* item is the item that can be access via the <span class="title-ref">DragItem</span> properties.

<div id="dragitem.nextitem">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.NextItem

**NextItem** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if there is another item that has been dragged and assigns the next item's values to the <span class="title-ref">DragItem</span> properties.
>
> Call this method on the dropped item to check if there are additional items you need to process. When called it, assigns the next item's values to the <span class="title-ref">DragItem</span> properties.

<div id="dragitem.pictureavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.PictureAvailable

**PictureAvailable** As `Boolean</api/data_types/boolean>`

> If `True</api/language/true>`, the *Picture* property contains a picture.
>
> The following code is in the DropObject event handler of an `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`. It tests whether a Picture has been dragged and, if so, assigns the dragged picture to the Image property of the `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`.
>
> ``` xojo
> If obj.PictureAvailable Then
>   Me.Image = obj.Picture
> ElseIf obj.FolderItemAvailable then
>   Me.Image = Picture.Open(obj.FolderItem)
> End If
> ```

<div id="dragitem.privaterawdata">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.PrivateRawData

**PrivateRawData**(macType As `String</api/data_types/string>`) As `String</api/data_types/string>`

**PrivateRawData**(macType As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Contains the raw data being dragged.
>
> The parameter is the file type being dragged. *macType* is a four-character resource type or programmer-defined four-character code. This data cannot be dragged to another application.
>
> This code checks for raw data of any type and does the drop.
>
> ``` xojo
> If obj.RawDataAvailable("????") Then
>   Me.Text = obj.PrivateRawData("????")
> End If
> ```

<div id="dragitem.rawdata">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.RawData

**RawData**(dataType As `String</api/data_types/string>`) As `String</api/data_types/string>`

> Contains the raw data being dragged.
>
> Checks if text data is in a a drag item:
>
> ``` xojo
> If dragObject.RawDataAvailable("public.text") Then
>   Me.Text = dragObject.RawData("public.text") ' UTI
> End If
> ```
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> On Windows, HTML data is supported using a [special format](https://learn.microsoft.com/en-us/windows/win32/dataxchg/html-clipboard-format).
>
> </div>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

**RawData**(dataType As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Contains the raw data being dragged.
>
> The *dataType* parameter supports both the older MacType and newer UTIs. If the *dataType* parameter is exactly 4 bytes then it is treated as a MacType for backwards compatibility. Otherwise it is treated as a UTI.
>
> On macOS, assigning "public.file-url" as the *dataType* and a non-empty `String</api/data_types/string>` as the *value* will write the *value* to the file at the `destination<dragitem.destination>`.

<div id="dragitem.rawdataavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.RawDataAvailable

**RawDataAvailable**(macType As `String</api/data_types/string>`) As `Boolean</api/data_types/boolean>`

> If `True</api/language/true>`, the <span class="title-ref">DragItem</span> contains data of the type or UTI specified.
>
> The *macType* parameter supports both the older MacType and newer UTIs. If the *macType* parameter is exactly 4 bytes then it is treated as a MacType for backwards compatibility. Otherwise it is treated as a UTI.
>
> Checks if text data is in a a drag item:
>
> ``` xojo
> If dragObject.RawDataAvailable("public.text") Then
>   Me.Text = dragObject.RawData("public.text") ' UTI
> End If
> ```

<div id="dragitem.textavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

DragItem.TextAvailable

**TextAvailable** As `Boolean</api/data_types/boolean>`

> If `True</api/language/true>`, the Text property contains text.
>
> The object that is receiving dragged text needs to be capable of receiving the text. This is enabled by calling AcceptTextDrop in the Opening event. In the DropObject event, you can test the TextAvailable property prior to dropping the text. For example:
>
> ``` xojo
> Do
>   If obj.TextAvailable Then
>     Me.AddRow(obj.Text)
>   End If
> Loop Until Not obj.NextItem
> ```

## Notes

When the user wishes to drag some data from a `DesktopWindow</api/user_interface/desktop/desktopwindow>` or `control</api/user_interface/desktop/desktopuicontrol>`, a new <span class="title-ref">DragItem</span> object must be created to hold that data in order to transfer it to the object the data will be dropped on. Xojo supports true drag and drop — which means that the recipient of the data can be anything that supports drag and drop and supports the kind of data being dragged. For example, text can be dragged to the desktop to create a text clipping file or any application that accepts dropped text (like SimpleText or the NotePad). Pictures can be dragged to the Desktop to create picture clipping files. Other types of data can be dragged using the RawData property.

The <span class="title-ref">DragItem</span> supports `UTIs \(Uniform Type Identifiers\)</topics/file_management/understanding_uniform_type_identifiers>`.

By default, a <span class="title-ref">DragItem</span> can contain only one row containing a single entry for each data type. Using the AddItem method, you can add more rows to the <span class="title-ref">DragItem</span> allowing multiple entries of the same data type. For example, if you wanted a drag item to contain two separate pictures, you would assign one picture to the Picture property then call the AddItem method to add a row and then assign the second picture to the Picture property.

The RawData and PrivateRawData properties allow you to support drag and drop for other data formats. You specify the data format using a four-character Type, corresponding to a macOS resource type. RawData and PrivateRawData return the dragged item as a `string</api/data_types/string>`. It is up to the control or window that receives the <span class="title-ref">DragItem</span> to manage it. Typically, this will mean that you will have to make API calls or use a plug-in that is designed to handle the data format.

You can also use RawData or PrivateRawData to control internal drag and drop. If you make up a four-character Type (not an existing macOS resource type), you can prevent a control from receiving dragged text from other sources. See the example of dragging from one `DesktopListBox</api/user_interface/desktop/desktoplistbox>` to another.

There is no need to create a <span class="title-ref">DragItem</span> for `TextAreas</api/user_interface/desktop/desktoptextarea>` as this is handled automatically.

`ListBoxes</api/user_interface/desktop/desktoplistbox>` support the dragging of rows automatically if the EnableDrag property of the `DesktopListBox</api/user_interface/desktop/desktoplistbox>` is `True</api/language/true>` (checked). Like `TextAreas</api/user_interface/desktop/desktoptextarea>`, the <span class="title-ref">DragItem</span> is created automatically for the ListBox but you must populate the <span class="title-ref">DragItem</span> in the DragRow event handler. See the notes for the `DesktopListBox</api/user_interface/desktop/desktoplistbox>` control for more information on dragging from ListBoxes.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Displaying drag pictures when there are multiple drag items

When there are multiple items in the <span class="title-ref">DragItem</span>, You can provide the drag picture in two ways: Using the constructor or by using the <span class="title-ref">DragItem</span> property.

If you use the constructor to provide a single picture, then on MacOS, this picture will be 3D stacked to indicate that there are multiple items. Since the same picture will be stacked in this manner it should be somewhat generic.

Alternatively you can not provide the picture in the constructor and then set the DragPicture property for each <span class="title-ref">DragItem</span> you add with AddItem. On MacOS this results in these separate images being vertically stacked to indicate each item being dragged. This can be more useful if your individual drag items are unique or distinct.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Dragging promised files

MacOS supports the concept of dragging a file before it actually exists in the file system. It could be a new document that hasn't been saved yet or a file that exists on a remote server or on the web.

In these cases, the drag and drop gesture serves the purpose of specifying the location at which to save the new file. When the drag and drop operation is complete, it tells the source where it wants the files saved and the dragging source creates the files. This special type of file drag is called a promise because the drag operation contains a promise from the source to the destination that the source will create the specified files if the drag and drop is accepted.

To drag and drop promised files, call the `DesktopUIControl</api/user_interface/desktop/desktopuicontrol>` or `DesktopWindow</api/user_interface/desktop/desktopwindow>`'s AcceptRawDataDrop method with "phfs"; as the data type. When an application that sends file promises is dropped on your application, you will find a `FolderItem</api/files/folderitem>` in the dragged item. Usually this will point to a file in the TemporaryItems folder and you should ordinarily delete it when you are finished with it.

## Sample code

This code shows how to implement dragging the picture in a `DesktopCanvas</api/user_interface/desktop/desktopcanvas>` control. This example uses the `Me</api/language/me>` keyword to refer to the `DesktopCanvas</api/user_interface/desktop/desktopcanvas>` control.

``` xojo
Function MouseDown(X As Integer, Y As Integer) As Boolean
  Var d As New DragItem(Self, X, Y, Me.Width, Me.Height)

  d.Picture = Me.Backdrop

  d.Drag ' Allow the drag
End Function
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

See also the example for `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`, which illustrates drag and drop between two ImageViewers and jpeg files or clippings on the desktop and the `DesktopListBox</api/user_interface/desktop/desktoplistbox>` control, which has an example of drag and drop between two ListBoxes.

The following code implements a "mover" interface in which a user can drag rows from ListBox1 to ListBox2 (and in the reverse direction), but neither `DesktopListBox</api/user_interface/desktop/desktoplistbox>` accepts dragged text from other controls or from other apps. It uses PrivateRawData since it also prevents text from being dragged outside the application.

To permit drag and drop in both directions, the two `ListBoxes</api/user_interface/desktop/desktoplistbox>` are set up in an identical manner.

Each `DesktopListBox</api/user_interface/desktop/desktoplistbox>` has its EnableDrag property set to `True</api/language/true>`. The DragRow event handler is:

``` xojo
Function DragRow(drag As DragItem, row As Integer) As Boolean
  drag.PrivateRawData("text") = Me.List(row) + EndOfLine ' get the text
  Me.RemoveRow(Row)
  Return True ' allow the drag
End Function
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

To enable each `DesktopListBox</api/user_interface/desktop/desktoplistbox>` to accept the dragged text, the following statement appears in its Opening event handler:

``` xojo
Me.AcceptRawDataDrop("text")
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The DropObject event handler is as follows:

``` xojo
Sub DropObject (obj As DragItem)
  If obj.RawDataAvailable("text") Then
    Me.AddRow(obj.RawData("text"))
  End If
End Sub
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following code allows the user to drag several text files from the desktop to a `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`. The example places the contents of all the text files in the `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`, appending each file's contents to the Text property of the `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`.

To support several files, the NextItem function is used to determine whether there are any more files remaining to be dropped.

``` xojo
Var textStream As TextInputStream

If obj.FolderItemAvailable Then

  Do

    textStream = TextInputStream.Open(obj.FolderItem)
    Me.TextArea1.AddText(textStream.ReadAll)

  Loop Until Not obj.NextItem

End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The `DesktopTextArea</api/user_interface/desktop/desktoptextarea>` has the line:

``` xojo
Me.AcceptFileDrop(FileTypeGroup1.Text)
```

## Compatibility

|                       |         |
|-----------------------|---------|
| **Project Types**     | Desktop |
| **Operating Systems** | All     |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `DesktopCanvas</api/user_interface/desktop/desktopcanvas>`, `DesktopTextArea</api/user_interface/desktop/desktoptextarea>`, `DesktopImageViewer</api/user_interface/desktop/desktopimageviewer>`, `DesktopListBox</api/user_interface/desktop/desktoplistbox>` controls; `Picture</api/graphics/picture>`, `FileType</api/files/filetype>`, `FolderItem</api/files/folderitem>` classes; `Supporting Drag and Drop</topics/user_interface/desktop/supporting_drag_and_drop>` topic

</div>
