Solved

Drop an Excel spreadsheet into a Windows form

Posted on 2014-01-22
4
454 Views
Last Modified: 2014-01-22
Good morning. I would like to drop an Excel spreadsheet in one of my Windows forms. Is this possible?  If so; please guide me through it. If it makes any difference, I am running Visual Studio on a Windows 8, 64 bit PC.  Thank you for any help.  --  Joe
0
Comment
Question by:jampost
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:frankhelk
ID: 39799681
Windows Forms provide the following events for Drag&Drop operation:

DragEnter, DragDrop, DragLeave

The precise meanings are explained in the VisualStudio help, usually along with examples.

DragEnter is fired, when an object is drawn onto the form's area, and DragLeave when it is subsequently drawn outside - these might be used i.e. for changing the cursor shape. DragDrop is fired when the object is dropped onto the form.

When an event handler routine is called, it gets some arguments with information about the handled object (and some more things).

What you have to do is to analyze what had been dropped onto the form and take the correct actions. There's no predefined Drag&Drop interface for a specific dropped object type - you only get the info that something has been dropped onto your form and where to find the object data (i.e. file, clipboard content, image, any kind of object). You have to handle the access to the object on your own (even while surely some data handling is built in, but you have to code what is to be done).
0
 

Author Comment

by:jampost
ID: 39799760
frankhelk,

So you are saying that the Visual Studio "Toolbox" has a functional spreadsheet that can be added to a Windows form?
0
 
LVL 14

Accepted Solution

by:
frankhelk earned 500 total points
ID: 39799830
Sorry, no, you've misunderstood that.

The VS forms are able to receive events when an object is dragged and dropped. When the events are fired, the event handler routine gives you an object whith properties who allow you to determine the type of the object, the allowed actions, and some more things. If a file is dropped, it allows you i.e. to get the file name.

After that point you're simply on your own, means that if an Excel file is dropped, you have to extract the info about it from the object, open that file with whatever code you have at hand and transfer the data into a standard data structure which lets you work on it further down the road.

There are surely methods for accessing Excel files from VB, but you have to call them yourself and extract the data with them.

But don't forget to check first what you've got dropped in ... if it's not an Excel file, but an image, a clipboard snippet, an executable file, or whatever could be dropped, your interpretation code will fail.

Please have a look at these examples:

http://msdn.microsoft.com/en-us/library/aa289508%28v=vs.71%29.aspx

http://www.codeproject.com/Articles/9017/A-Simple-Drag-And-Drop-How-To-Example

http://www.codemag.com/Article/0803041

http://www.developerfusion.com/article/2692/drag-and-drop-in-windows-forms-a-primer/
0
 

Author Closing Comment

by:jampost
ID: 39801850
Thank you,  I'll find a work around for this.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question