-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.vb
65 lines (56 loc) · 2.78 KB
/
MainWindow.xaml.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Imports DevExpress.Xpf.Core
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports System.Windows.Media
Namespace How_to_Drag_and_Drop_Between_GridControl_and_Other_Controls
Public Partial Class MainWindow
Inherits Window
Public Sub New()
Me.InitializeComponent()
Me.gridControl.ItemsSource = Staff.GetStaff()
End Sub
Private Overloads Sub OnDragEnter(ByVal sender As Object, ByVal e As DragEventArgs)
If e.Data.GetDataPresent(GetType(RecordDragDropData)) Then
Dim textBlock As TextBlock = CType(sender, TextBlock)
textBlock.Background = Brushes.SkyBlue
e.Handled = True
End If
End Sub
Private Overloads Sub OnDragLeave(ByVal sender As Object, ByVal e As DragEventArgs)
Dim textBlock As TextBlock = CType(sender, TextBlock)
textBlock.Background = Nothing
textBlock.DataContext = Nothing
e.Handled = True
End Sub
Private Overloads Sub OnDrop(ByVal sender As Object, ByVal e As DragEventArgs)
If e.Data.GetDataPresent(GetType(RecordDragDropData)) Then
Dim textBlock As TextBlock = CType(sender, TextBlock)
Dim data As Object = e.Data.GetData(GetType(RecordDragDropData))
Dim employees As Object() = CType(data, RecordDragDropData).Records
textBlock.DataContext = CType(CType(employees, IList)(0), Employee)
End If
End Sub
Private Overloads Sub OnPreviewMouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
Dim textBlock As TextBlock = CType(sender, TextBlock)
If textBlock.DataContext IsNot Nothing Then
DragDrop.DoDragDrop(textBlock, textBlock.DataContext, DragDropEffects.Move)
End If
End Sub
Private Sub OnDragRecordOver(ByVal sender As Object, ByVal e As DragRecordOverEventArgs)
If e.IsFromOutside AndAlso e.Data.GetDataPresent(GetType(Employee)) Then
e.Effects = DragDropEffects.Move
e.Handled = True
End If
End Sub
Private Sub OnDropRecord(ByVal sender As Object, ByVal e As DropRecordEventArgs)
If e.IsFromOutside AndAlso e.Data.GetDataPresent(GetType(Employee)) Then
Dim data As Object = e.Data.GetData(GetType(Employee))
Dim employee As Employee = CType(data, Employee)
e.Data.SetData(New RecordDragDropData(New List(Of Employee)() From {employee}.ToArray()))
End If
End Sub
End Class
End Namespace