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.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Event Data
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. |
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.
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; }
}
Related GitHub Examples
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.