Solved

Drop an Excel spreadsheet into a Windows form

Posted on 2014-01-22
4
500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 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