2012年6月2日 星期六

Drag and drop a filename into a DataGridView

參考引用
--
     Private Sub TblSheepGroupPhotosDataGridView_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TblSheepGroupPhotosDataGridView.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.All
        End If
    End Sub

    Private Sub TblSheepGroupPhotosDataGridView_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TblSheepGroupPhotosDataGridView.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim PhotoFiles() As String
            Dim i As Integer

            ' Assign the files to an array.
            PhotoFiles = e.Data.GetData(DataFormats.FileDrop)
            ' Loop through the array and add the files to the list.
            For i = 0 To PhotoFiles.Length - 1
                Dim CurrentFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(PhotoFiles(i).ToString)
                MsgBox("INSERT INTO tblSheepGroupPhotos(Filename) VALUES('" & CurrentFile.Name & "';")
            Next
        End If
    End Sub

沒有留言:

張貼留言