This example demonstrates how to use drag-and-drop events to customize the drag-and-drop behavior in the GridControl.
A drag-and-drop operation changes the Position and Department values based on the dropped record's new location.
Files to Look At
Documentation
More Examples
- WPF Data Grid - Implement Drag-and-Drop Between the GridControl and Other Controls
- WPF Data Grid - Customize the Drop Marker
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
XAML<Window x:Class="WPF_GridControl_Custom_Drag_and_Drop.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="350" Width="525">
<dxg:GridControl Name="gridControl" SelectionMode="Row" AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TreeListView KeyFieldName="ID"
ParentFieldName="ParentID"
AutoExpandAllNodes="True"
AllowDragDrop="True"
DropRecord="OnDropRecord"/>
</dxg:GridControl.View>
</dxg:GridControl>
</Window>
C#using DevExpress.Xpf.Core;
using System.Windows;
namespace WPF_GridControl_Custom_Drag_and_Drop {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
gridControl.ItemsSource = Staff.GetStaff();
}
void OnDropRecord(object sender, DropRecordEventArgs e) {
object data = e.Data.GetData(typeof(RecordDragDropData));
foreach (Employee employee in ((RecordDragDropData)data).Records) {
employee.Position = ((Employee)e.TargetRecord).Position;
employee.Department = ((Employee)e.TargetRecord).Department;
}
if (e.DropPosition == DropPosition.Inside) {
foreach(Employee employee in ((RecordDragDropData)data).Records) {
employee.Position = "";
}
}
}
}
}