Drag and Drop Flexcell 3

Hello Adrian I am still yet to use version 5 because my application uses the old flexcell sheets a lot.

I am adding a new feature to the application and I would like to ask your advise before spending the time to develop.

What I want to do is with a TlistBox items simply allow the user to drag and drop those items into cells on the flexcell sheet.

I then want to be able to manipulate the dropped item in code as required and add cell formatting based on the dropped item value.

However I want to restrict the dropping of items to a range of rows and columns

Then I want to make sure the dropped items get saved when I export to xls.

Is there a demo which shows this procedure?

Many Thanks

Hi,

The first question would be: Do you want "Real" drag and drop or "VCL" drag and drop?

By default, the DragAndDrop events in delphi are just for the same app. But it won't work in the general case, like for example someone dragging some cells from Excel and dropping them in your app, or dragging from your app and dropping them in Excel. This just won't work with VCL drag and drop, and it is the main reason why we don't support it natively in the grid (as we support copy and paste). 

To make some "real" drag an drop, you need to use some third party library like:
http://melander.dk/delphi/dragdrop/

And the "hard" part of the work is in getting drag and drop to work, not in the FlexCel side. Once you have htis working there is some kind of "OnDragOver" event where you can decide if you choose to accept or not the items the user is dragging, Then other event "OnDragDrop" or similar you fill the FlexCelImport attached to the grid with the values and call Grid.LoadSheet so the grid is refreshed.

There have been many years since I last coded a drag and drop, so I might get some detail wrong, but this is the idea. FlexCel supports Copy and Paste (and there is a demo showing it), I believe that the format for drag and drop is the same, so it might be possible to reuse that code.

Also remember that FlexCelGrid is just a "TCustomGrid" descendant, so any code you have to drag and drop into a normal grid should work in FlexCelGrid too.

But as said, the first step is to define if you want "real" drag and drop, and if this is the case, you will have to start by getting some drag and drop solution like the one I mentioned.

Regards,
   Adrian.

Hello Adrian thanks for taking the time to reply.

For the moment, Its drag and drop from within the same VCL application.

Do you remember which demo do i need to look at?

Thanks

Hi, 

The demo is on Copy and paste, not drag and drop. (and it is Demo\Modules\10.API\40.Copy And Paste )

But if all you are interested is in drag and drop in the same app, then using the standard VCL OnDragEnter and OnDragDrop should be simple enough.

I uploaded a simple demo on how to do it here:
http://tmssoftware.net/public/flexcel/samples/DragAndDrop.zip

It will allow you to drag the label at the left to columns D or E only. If you want to drag something different than a label, then change the (source is TLabel) by whatever VCL objects they are (source is TMemo, etc).

Other than that, I made the label to have "autodrag" so you can drag it with the mouse.

Regards,
   Adrian.

Fantastic that simple demo is perfect to get me going.

Thank you so much.