Get DataGridView to accept file drop from mapped drive

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
code20runner
Posts: 10
Joined: Wed Mar 21, 2018 8:48 am

Get DataGridView to accept file drop from mapped drive

Post by code20runner » Mon Oct 01, 2018 1:06 pm

I have a project where I can drag and drop files and folders from a local drive to a DataGridView and everything works as expected. However, when I attempt to do the same with files from a mapped drive (UNC Path shared directory), the program locks up. How would I go about achieving this task?

User avatar
jvierra
Posts: 13297
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra » Mon Oct 01, 2018 1:10 pm

Have you tried to debug your code. There is no issue with dropping from a UNC. The code needs to grab the correct properties.

User avatar
code20runner
Posts: 10
Joined: Wed Mar 21, 2018 8:48 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner » Mon Oct 01, 2018 1:17 pm

Two issues with debugging. 1. My code machine is not attached to a network where I can test the UNC path issue. 2. New to PowerShell Studio and not sure how to get the correct properties you mention.

User avatar
code20runner
Posts: 10
Joined: Wed Mar 21, 2018 8:48 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner » Mon Oct 01, 2018 1:29 pm

Ok. I got a mapped drive on my code machine. I ran the debugger but when I drag and drop a file from the mapped drive onto the DataGridView in my application, the debugger doesn't report any issues, it just locks up.

Below is my code for the DragDrop:

Code: Select all

$CollectDGV_DragDrop = [System.Windows.Forms.DragEventHandler]{

foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) # $_ = [System.Windows.Forms.DragEventArgs]
{
$eachFile = Get-ChildItem $filename -Recurse

foreach ($truefile in $eachFile | Where-Object { !$_.psiscontainer })
{
$size = [math]::Round($truefile.Length / 1MB, 1)
$CollectDGV.Rows.Add($truefile.FullName, $size)
}
}
$CollectStatusBar.Text = ("List contains $($CollectDGV.Rows.Count) items")
}

User avatar
jvierra
Posts: 13297
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra » Mon Oct 01, 2018 1:36 pm

Did you set a breakpoint?

User avatar
code20runner
Posts: 10
Joined: Wed Mar 21, 2018 8:48 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner » Mon Oct 01, 2018 2:24 pm

I don't see any breakpoints showing up or anything to indicate where the problem is located.

User avatar
jvierra
Posts: 13297
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra » Mon Oct 01, 2018 2:46 pm

You need to start by reviewing the debugging chapter in the product manual.

User avatar
code20runner
Posts: 10
Joined: Wed Mar 21, 2018 8:48 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner » Mon Oct 01, 2018 3:42 pm

Thanks for the guidance. However, my main issue isn't with debugging at the moment, it is understanding how to deal with/implement UNC Paths and DataGridViews.

User avatar
jvierra
Posts: 13297
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra » Mon Oct 01, 2018 4:33 pm

No idea what is meant by "implement UNC Paths and DataGridViews". A DataGridView does not know anything about UNC paths. Are you askng how to display a UNC path in a DGV?

User avatar
code20runner
Posts: 10
Joined: Wed Mar 21, 2018 8:48 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner » Mon Oct 01, 2018 6:10 pm

I figured out the issue of the application locking up when I drag and drop a file from a mapped drive to the DataGridView box. I had to ensure I was using the -LiteralPath option and not the -Path option. All seems to be working now.

Locked