首先打开表属性AllowDrop=True
DragMode=DragModeEnum.Manual
如果是模板窗体,可以考虑在表的AfterLoaded事件中写代码赋值。然后再写两个表事件DragEnter、DragDrop
注意:在程序在以管理员权限打开的情况下,拖拽功能的代码会失效,详情可参考:https://www.cnblogs.com/whr2071/p/15922643.html
- Public Sub SmGrid1_DragEnter(sender As Object,e As System.Windows.Forms.DragEventArgs)
- If e.Data.GetDataPresent(DataFormats.FileDrop) Then
- e.Effect = DragDropEffects.Link
- Else
- e.Effect = DragDropEffects.None
- End If
- End Sub
-
- Public Sub SmGrid1_DragDrop(sender As Object,e As System.Windows.Forms.DragEventArgs)
- Dim arr As Array = e.Data.GetData(DataFormats.FileDrop)
- Dim strFile As String=arr.GetValue(0).ToString()
- Dim tbl As SmGrid=sender
- If tbl.CurrentRowData IsNot Nothing Then
- tbl.CurrentRowData("CurrentAddress")=strFile
- 'tbl.CurrentRowData("仅文件名")=Path.GetFileName(strFile)
- End If
- End Sub
复制代码
|