DragDrop zip file onto DataGridView
-
Hi, I've got some code that allows me to click a button to browse to a zip file, and populate a DataGridView with all of the file names contained within the zip. What I now want to do is go a stage further, and allow the user to drag a zip file into the DataGridView, and perform the same routine. For reference, the functionality to perform the unzip is provided via DotNetZipLib.zip The code that I've been trying to get to work is:
Imports ionic.utils.zip Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop Dim strFilePathAndName As String strFilePathAndName = DirectCast(e.Data.GetData(Windows.Forms.DataFormats.FileDrop), String) Dim zip As ZipFile zip = ZipFile.Read(strFilePathAndName) Dim tblZipFilesTable As DataTable = New DataTable("CompressedFiles") Dim ds As DataSet = New DataSet("ZipFile") ds.Tables.Add(tblZipFilesTable) tblZipFilesTable.Columns.Add("File name", GetType(String)) tblZipFilesTable.Columns.Add("Columns in table", GetType(Integer)) Dim tblRow As DataRow For Each file As ZipEntry In zip tblRow = tblZipFilesTable.NewRow tblRow.Item("File name") = file.FileName.ToString tblZipFilesTable.Rows.Add(tblRow) Next Me.DataGridView1.DataSource = ds Me.DataGridView1.DataMember = "CompressedFiles" With Me.DataGridView1 .Columns(0).Width = 210 .Columns(1).Width = 120 End With Me.DataGridView1.Refresh() End Sub Private Sub DataGridView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragEnter If e.Data.GetDataPresent(Windows.Forms.DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub
But it doesn't do anything. When I set a breakpoint within the first few lines of "Sub DataGridView1_DragDrop", I find that it doesn't even go in here. -
Hi, I've got some code that allows me to click a button to browse to a zip file, and populate a DataGridView with all of the file names contained within the zip. What I now want to do is go a stage further, and allow the user to drag a zip file into the DataGridView, and perform the same routine. For reference, the functionality to perform the unzip is provided via DotNetZipLib.zip The code that I've been trying to get to work is:
Imports ionic.utils.zip Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop Dim strFilePathAndName As String strFilePathAndName = DirectCast(e.Data.GetData(Windows.Forms.DataFormats.FileDrop), String) Dim zip As ZipFile zip = ZipFile.Read(strFilePathAndName) Dim tblZipFilesTable As DataTable = New DataTable("CompressedFiles") Dim ds As DataSet = New DataSet("ZipFile") ds.Tables.Add(tblZipFilesTable) tblZipFilesTable.Columns.Add("File name", GetType(String)) tblZipFilesTable.Columns.Add("Columns in table", GetType(Integer)) Dim tblRow As DataRow For Each file As ZipEntry In zip tblRow = tblZipFilesTable.NewRow tblRow.Item("File name") = file.FileName.ToString tblZipFilesTable.Rows.Add(tblRow) Next Me.DataGridView1.DataSource = ds Me.DataGridView1.DataMember = "CompressedFiles" With Me.DataGridView1 .Columns(0).Width = 210 .Columns(1).Width = 120 End With Me.DataGridView1.Refresh() End Sub Private Sub DataGridView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragEnter If e.Data.GetDataPresent(Windows.Forms.DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub
But it doesn't do anything. When I set a breakpoint within the first few lines of "Sub DataGridView1_DragDrop", I find that it doesn't even go in here.Resolved it ...
Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop Dim strFilePathAndName As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()) Dim zip As ZipFile zip = ZipFile.Read(strFilePathAndName(0))