2016-07-06 82 views
0

我試圖使用Windows窗體DataGridView,因爲它看起來WPF DataGrid不允許獲取選擇並且缺少獲取當前列和行索引等功能。使用WPF + Windows窗體拖放

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

我用這個解決方法的問題是,該元素看起來不接受拖放,光標變成停止標誌。

任何建議我需要做些什麼才能打開DataGridView

回答

0

我落得這樣做,不知道這是否是「正確的方式」來處理這種情況:

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