Solved

Drop an Excel spreadsheet into a Windows form

Posted on 2014-01-22
4
414 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 13

Expert Comment

by:frankhelk
Comment Utility
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
Comment Utility
frankhelk,

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

Accepted Solution

by:
frankhelk earned 500 total points
Comment Utility
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
Comment Utility
Thank you,  I'll find a work around for this.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now