windowsforms-devexpress-dot-xtragrid-dot-views-dot-tile-dot-tileview-9ee62e97.md
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
[DXCategory("Action")]
public event TileViewBeforeItemDropEventHandler BeforeItemDrop
<DXCategory("Action")>
Public Event BeforeItemDrop As TileViewBeforeItemDropEventHandler
The BeforeItemDrop event's data class is BeforeItemDropEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| GroupColumnValue | Gets the value of the current group from which the tile has been dragged. |
| GroupRowHandle | Gets the handle of the group from which the tile has been dragged. |
| Handled | Gets 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. |
| IndexInGroup | Gets the visible index of the current tile in its original group. |
| KanbanGroup | Gets 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. |
| ListSourceRowIndex | Gets the tile’s index in the data source. |
| NewGroupColumnValue | Gets the value of the new group to which the tile is about to be dropped. |
| NewGroupRowHandle | Gets the handle of the group to which the tile is dropped. |
| NewKanbanGroup | Gets 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. |
| NewListSourceRowIndex | Gets the tile’s new index in the data source at which the tile is about to be inserted. |
| RowHandle | Gets the current row handle of the tile. |
| TargetIndexInGroup | Gets the position at which the current item is about to be dropped within the target group. |
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:
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 ).
The following example demonstrates how to handle the BeforeItemDrop event to identify the tile below the dragged tile when the latter is dropped.
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; }
}
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
tileView1.BeforeItemDrop += TileView1_BeforeItemDrop;
}
winforms-grid-reorder-tileview-cards-sql/VB/Reorder/Form1.vb#L18
gridControl1.DataSource = DataHelper.GetData()
AddHandler tileView1.BeforeItemDrop, AddressOf TileView1_BeforeItemDrop
End Sub
See Also
BeforeItemDrop