Common/GridBuilder: Add WithClipboardHandler

This commit is contained in:
Jonathan Jenne 2021-10-04 14:15:52 +02:00
parent e6b9bc30df
commit 9578a36b41

View File

@ -1,4 +1,5 @@
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraTreeList
@ -80,4 +81,28 @@ Public Class GridBuilder
Return Me
End Function
Public Function WithClipboardHandler() As GridBuilder
For Each oGridView In Views
WithClipboardHandler(oGridView)
Next
Return Me
End Function
Public Function WithClipboardHandler(View As GridView) As GridBuilder
AddHandler View.KeyDown, AddressOf GridView_ClipboardHandler
Return Me
End Function
Private Sub GridView_ClipboardHandler(sender As Object, e As KeyEventArgs)
Dim view As GridView = CType(sender, GridView)
If e.Control AndAlso e.KeyCode = Keys.C Then
If view.GetRowCellValue(view.FocusedRowHandle, view.FocusedColumn) IsNot Nothing AndAlso view.GetRowCellValue(view.FocusedRowHandle, view.FocusedColumn).ToString() <> [String].Empty Then
Clipboard.SetText(view.GetRowCellValue(view.FocusedRowHandle, view.FocusedColumn).ToString())
End If
e.Handled = True
End If
End Sub
End Class