Back to Devexpress

TileView.BeforeItemDrop Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-tile-dot-tileview-9ee62e97.md

latest11.4 KB
Original Source

TileView.BeforeItemDrop Event

Fires when a tile drop operation is initiated. This event does not fire when you enable drag-and-drop using Drag And Drop Behavior.

Namespace : DevExpress.XtraGrid.Views.Tile

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Action")]
public event TileViewBeforeItemDropEventHandler BeforeItemDrop
vb
<DXCategory("Action")>
Public Event BeforeItemDrop As TileViewBeforeItemDropEventHandler

Event Data

The BeforeItemDrop event's data class is BeforeItemDropEventArgs. The following properties provide information specific to this event:

PropertyDescription
GroupColumnValueGets the value of the current group from which the tile has been dragged.
GroupRowHandleGets the handle of the group from which the tile has been dragged.
HandledGets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs.
IndexInGroupGets the visible index of the current tile in its original group.
KanbanGroupGets the KanbanGroup that owns the current tile. This property is in effect if you created KanbanGroups via the TileViewOptionsKanban.Groups collection. Otherwise, this property returns null.
ListSourceRowIndexGets the tile’s index in the data source.
NewGroupColumnValueGets the value of the new group to which the tile is about to be dropped.
NewGroupRowHandleGets the handle of the group to which the tile is dropped.
NewKanbanGroupGets the KanbanGroup to which the tile is about to be dropped. This property is in effect if you created KanbanGroups via the TileViewOptionsKanban.Groups collection. Otherwise, this property returns null.
NewListSourceRowIndexGets the tile’s new index in the data source at which the tile is about to be inserted.
RowHandleGets the current row handle of the tile.
TargetIndexInGroupGets the position at which the current item is about to be dropped within the target group.

Remarks

Use the TileView.OptionsDragDrop.AllowDrag setting to enable the built-in tile drag-and-drop feature.

Tile drag-and-drop operations are reflected on the data source level. When a tile is dropped at a certain position, the Tile View fires the BeforeItemDrop event just before moving the tile’s underlying data record to new position ( NewListSourceRowIndex ) in the data source. You can handle the BeforeItemDrop event to do the following:

  • Move the tile’s record to a custom position, instead of the calculated position. To accomplish this, assign a new record position to the BeforeItemDropEventArgs.NewListSourceRowIndex property, and leave the event’s Handled parameter set to false. The Tile View will move the record to the specified position after your BeforeItemDrop event handler is complete.
  • Manually move the tile’s record to a new position using the methods provided by your data source. Don’t forget to set the event’s Handled parameter to true , to indicate that no default processing is required after your BeforeItemDrop event handler is completed.

Tiles can be combined into groups by specifying the group column (TileViewColumns.GroupColumn). If a tile is moved from one group to another group, the underlying record’s group field ( GroupColumn.FieldName ) needs to be changed accordingly. After your BeforeItemDrop event handler is complete, the Tile View will set the underlying record’s group field to the NewGroupColumnValue parameter value (provided that the event’s Handled parameter is false ).

Example

The following example demonstrates how to handle the BeforeItemDrop event to identify the tile below the dragged tile when the latter is dropped.

csharp
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Tile;

private void TileView1_BeforeItemDrop(object sender, BeforeItemDropEventArgs e) {
    TileView view = sender as TileView;
    int newParentRowHandle = GetParentRowHandleFromGroupColumnValue(view, e.NewGroupColumnValue);
    if(view.IsValidRowHandle(newParentRowHandle)) {
        int tileAfterRowHandle = view.GetChildRowHandle(newParentRowHandle, e.TargetIndexInGroup);
        TaskRecord tileAfter = (TaskRecord)view.GetRow(tileAfterRowHandle);
        MessageBox.Show(tileAfter.Description);
    }
}
private int GetParentRowHandleFromGroupColumnValue(TileView view, object groupColumnValue) {
    // Iterates through the rows and looks for a row that matches the group column value.
    // Returns the row's parent row handle.
    for(int rowHandle = 0; rowHandle < view.DataRowCount; rowHandle++) {
        TaskRecord row = (TaskRecord)view.GetRow(rowHandle);
        if (row.Status.Equals(groupColumnValue)) {
            int parentRowHandle = view.GetParentRowHandle(rowHandle);

            if (view.IsGroupRow(parentRowHandle))
                return parentRowHandle;
        }
    }
    return GridControl.InvalidRowHandle;
}

// ...
public enum TaskStatus { ToDo, Planned, Doing, Testing, Done }
public class TaskRecord {
    public string Caption { get; set; }
    public string Description { get; set; }
    public Image AttachedImage { get; set; }
    public TaskStatus Status { get; set; }
}
vb
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Tile

Private Sub TileView1_BeforeItemDrop(ByVal sender As Object, ByVal e As BeforeItemDropEventArgs)
    Dim view As TileView = TryCast(sender, TileView)
    Dim newParentRowHandle As Integer = GetParentRowHandleFromGroupColumnValue(view, e.NewGroupColumnValue)
    If view.IsValidRowHandle(newParentRowHandle) Then
        Dim tileAfterRowHandle As Integer = view.GetChildRowHandle(newParentRowHandle, e.TargetIndexInGroup)
        Dim tileAfter As TaskRecord = CType(view.GetRow(tileAfterRowHandle), TaskRecord)
        MessageBox.Show(tileAfter.Description)
    End If
End Sub
Private Function GetParentRowHandleFromGroupColumnValue(ByVal view As TileView, ByVal groupColumnValue As Object) As Integer
    ' Iterates through the rows and looks for a row that matches the group column value.
    ' Returns the row's parent row handle.
    For rowHandle As Integer = 0 To view.DataRowCount - 1
        Dim row As TaskRecord = CType(view.GetRow(rowHandle), TaskRecord)
        If row.Status.Equals(groupColumnValue) Then
            Dim parentRowHandle As Integer = view.GetParentRowHandle(rowHandle)

            If view.IsGroupRow(parentRowHandle) Then
                Return parentRowHandle
            End If
        End If
    Next rowHandle
    Return GridControl.InvalidRowHandle
End Function

' ...
Public Enum TaskStatus
    ToDo
    Planned
    Doing
    Testing
    Done
End Enum
Public Class TaskRecord
    Public Property Caption() As String
    Public Property Description() As String
    Public Property AttachedImage() As Image
    Public Property Status() As TaskStatus
End Class

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the BeforeItemDrop event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-reorder-tileview-cards-sql/CS/Reorder/Form1.cs#L19

csharp
tileView1.BeforeItemDrop += TileView1_BeforeItemDrop;
}

winforms-grid-reorder-tileview-cards-sql/VB/Reorder/Form1.vb#L18

vb
gridControl1.DataSource = DataHelper.GetData()
    AddHandler tileView1.BeforeItemDrop, AddressOf TileView1_BeforeItemDrop
End Sub

See Also

ColumnSet

AllowDrag

AllowItemDrag

DropTargetGroups

BeforeItemDrag

BeforeItemDrop

ItemDrag

ItemDrop

TileView Class

TileView Members

DevExpress.XtraGrid.Views.Tile Namespace