473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Grab filename from drag&drop into ListView? How?

Hi,

In VB.NET, how do I determine what filename has been dropped into a ListView?

In my ListView's DragEnter() event, I am trying this, which according to the Help,
should work:

MyFilename = e.Data.GetData("FileName").ToString
I have also tried e.Data.GetData(DataFormats.Text) and GetData(System.String)...
neither work. I keep getting "System.String[]" back as the filename.

I have used e.GetData.GetFormats() to get a list of the formats, and I see the
following:

Shell IDList Array
DragImageBits
DragContext
Shell Object Offsets
InShellDragLoop
FileDrop
FileName
FileNameW

I have tried using all of them to no avail. Some return "System.IO.MemoryStream".

Those last two lead me to believe that I should be able to specify GetData("FileName")
to get the filename, but it doesn't work. What am I doing wrong?

Ken
Nov 20 '05 #1
4 5549
Ken,

It all depends on what "e" is. I'm only guessing, but is "e" a reference to
the ListView control that is raising the event? Why not put a breakpoint
here, get into the Command - Immediate window and rip the puppy apart with
stuff like

? e.text
? e.Data
? e.TryingToTellMe

You might just hit on the right combination of properties and methods.
"Ken Swanson" <hy*****@comcast.net> wrote in message
news:pef%b.21199$AL.421858@attbi_s03...
Hi,

In VB.NET, how do I determine what filename has been dropped into a ListView?
In my ListView's DragEnter() event, I am trying this, which according to the Help, should work:

MyFilename = e.Data.GetData("FileName").ToString
I have also tried e.Data.GetData(DataFormats.Text) and GetData(System.String)... neither work. I keep getting "System.String[]" back as the filename.

I have used e.GetData.GetFormats() to get a list of the formats, and I see the following:

Shell IDList Array
DragImageBits
DragContext
Shell Object Offsets
InShellDragLoop
FileDrop
FileName
FileNameW

I have tried using all of them to no avail. Some return "System.IO.MemoryStream".
Those last two lead me to believe that I should be able to specify GetData("FileName") to get the filename, but it doesn't work. What am I doing wrong?

Ken

Nov 20 '05 #2
Ken,
I take it you are dragging & dropping a file from Windows Explorer?

You will receive an array of string (System.String[]) which contains the
list of filenames (might be a list of 1 or a list of 100).

Try something like (untested):

Dim fileNames() as String
Dim MyFilename As String
fileNames= DirectCast(e.Data.GetData(DataFormats.FileDrop), String())

MyFilename = fileNames(0)

Charles Petzold's book "Programming Microsoft Windows With Microsoft Visual
Basic.NET" from MS Press, has a long discussion on using Drag & Drop and
what formats work with .NET and how to use them.

Hope this helps
Jay

"Ken Swanson" <hy*****@comcast.net> wrote in message
news:pef%b.21199$AL.421858@attbi_s03...
Hi,

In VB.NET, how do I determine what filename has been dropped into a ListView?
In my ListView's DragEnter() event, I am trying this, which according to the Help, should work:

MyFilename = e.Data.GetData("FileName").ToString
I have also tried e.Data.GetData(DataFormats.Text) and GetData(System.String)... neither work. I keep getting "System.String[]" back as the filename.

I have used e.GetData.GetFormats() to get a list of the formats, and I see the following:

Shell IDList Array
DragImageBits
DragContext
Shell Object Offsets
InShellDragLoop
FileDrop
FileName
FileNameW

I have tried using all of them to no avail. Some return "System.IO.MemoryStream".
Those last two lead me to believe that I should be able to specify GetData("FileName") to get the filename, but it doesn't work. What am I doing wrong?

Ken

Nov 20 '05 #3
Thanks for the responses. Both are good suggestions.

e is a reference to System.Windows.Forms.DragEventArgs.

I had tried to get an array of strings, since it looked like it was telling
me it was an array, but I'm new to VB and couldn't quite get it. Maybe
that DirectCast function below will help!

Thanks,

Ken
Jay B. Harlow [MVP - Outlook] wrote:
Ken,
I take it you are dragging & dropping a file from Windows Explorer?

You will receive an array of string (System.String[]) which contains the
list of filenames (might be a list of 1 or a list of 100).

Try something like (untested):

Dim fileNames() as String
Dim MyFilename As String
fileNames= DirectCast(e.Data.GetData(DataFormats.FileDrop), String())

MyFilename = fileNames(0)

Charles Petzold's book "Programming Microsoft Windows With Microsoft Visual
Basic.NET" from MS Press, has a long discussion on using Drag & Drop and
what formats work with .NET and how to use them.

Hope this helps
Jay

"Ken Swanson" <hy*****@comcast.net> wrote in message
news:pef%b.21199$AL.421858@attbi_s03...
Hi,

In VB.NET, how do I determine what filename has been dropped into a


ListView?
In my ListView's DragEnter() event, I am trying this, which according to


the Help,
should work:

MyFilename = e.Data.GetData("FileName").ToString
I have also tried e.Data.GetData(DataFormats.Text) and


GetData(System.String)...
neither work. I keep getting "System.String[]" back as the filename.

I have used e.GetData.GetFormats() to get a list of the formats, and I see


the
following:

Shell IDList Array
DragImageBits
DragContext
Shell Object Offsets
InShellDragLoop
FileDrop
FileName
FileNameW

I have tried using all of them to no avail. Some return


"System.IO.MemoryStream".
Those last two lead me to believe that I should be able to specify


GetData("FileName")
to get the filename, but it doesn't work. What am I doing wrong?

Ken



Nov 20 '05 #4
Bingo! Much thanks, Jay.

I didn't know about DirectCast().

Ken

Jay B. Harlow [MVP - Outlook] wrote:
Ken,
I take it you are dragging & dropping a file from Windows Explorer?

You will receive an array of string (System.String[]) which contains the
list of filenames (might be a list of 1 or a list of 100).

Try something like (untested):

Dim fileNames() as String
Dim MyFilename As String
fileNames= DirectCast(e.Data.GetData(DataFormats.FileDrop), String())

MyFilename = fileNames(0)

Charles Petzold's book "Programming Microsoft Windows With Microsoft Visual
Basic.NET" from MS Press, has a long discussion on using Drag & Drop and
what formats work with .NET and how to use them.

Hope this helps
Jay

"Ken Swanson" <hy*****@comcast.net> wrote in message
news:pef%b.21199$AL.421858@attbi_s03...
Hi,

In VB.NET, how do I determine what filename has been dropped into a


ListView?
In my ListView's DragEnter() event, I am trying this, which according to


the Help,
should work:

MyFilename = e.Data.GetData("FileName").ToString
I have also tried e.Data.GetData(DataFormats.Text) and


GetData(System.String)...
neither work. I keep getting "System.String[]" back as the filename.

I have used e.GetData.GetFormats() to get a list of the formats, and I see


the
following:

Shell IDList Array
DragImageBits
DragContext
Shell Object Offsets
InShellDragLoop
FileDrop
FileName
FileNameW

I have tried using all of them to no avail. Some return


"System.IO.MemoryStream".
Those last two lead me to believe that I should be able to specify


GetData("FileName")
to get the filename, but it doesn't work. What am I doing wrong?

Ken



Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Plumer | last post by:
Hello everyone, This is a note that continues the saga of implementing drag & drop in a TreeView (and, presumably, a ListView as well). When DoDragDrop() is called the framework takes over the...
2
by: Grey | last post by:
I need to design a workflow application with C#. I want to design an UI with some workflow components which they can be drag & drop anywhere in order to design the workflow for the application...
0
by: Andy | last post by:
Hi all, I'm developing an application which allows a drag and drop of files onto a ListView control. Everything works fine on my Windows XP development computer, but when i move the...
1
by: Neil West | last post by:
I’m trying to drag & drop listview items between two instances of my app. The actual data that’s passed in DoDragDrop is an arraylist that’s been serialized to a memorystream. The contents...
1
by: Terry Olsen | last post by:
My first time using TreeViews. I have TreeView1 set up to display my directory structure just like Windows Explorer. I can drag & drop files and folders over to TreeView2. I can re-arrange the...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
1
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: ...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
4
by: =?Utf-8?B?anV2aQ==?= | last post by:
Hello, I have successfully used the sample provided in msdn for creating darg&drop between 2 listviews. Is this possible for more than 2 listviews? I have listview A,B and C and I want to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.