【问题标题】:Drag and drop with WPF + Windows Forms使用 WPF + Windows 窗体拖放
【发布时间】:2016-11-08 05:51:01
【问题描述】:

我正在尝试使用 Windows 窗体 DataGridView,因为 WPF DataGrid 似乎不允许获取选择并且缺少获取当前列和行索引等功能。

<WindowsFormsHost Name="wfhFileEditorWindow" DockPanel.Dock="Top" AllowDrop="True" >
   <WindowsFormsHost.Child>
      <wf:DataGridView x:Name="dgFileEditorWindow" AllowDrop="True">
      </wf:DataGridView>
   </WindowsFormsHost.Child>
</WindowsFormsHost>

这个解决方法的问题是元素似乎不接受拖放,光标变成停止标志。

有什么建议我需要做些什么来启用DataGridView吗?

【问题讨论】:

    标签: wpf vb.net winforms drag-and-drop


    【解决方案1】:

    我最终这样做了,不确定这是否是处理这种情况的“正确方法”:

    Private Sub dgFileEditorWindow_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dgFileEditorWindow.DragEnter
        If (e.Data.GetDataPresent(DataFormats.Text)) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub
    
    Private Sub dgFileEditorWindow_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dgFileEditorWindow.DragDrop
        Dim filename As String = e.Data.GetData(DataFormats.Text).ToString()
        If loadCSVfileToDataGridView(filename, dgFileEditorWindow) Then
            editedFile_Filename = filename
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多