Jump to content


Photo

Drop Explorer Files on a TGridView


  • Please log in to reply
3 replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 18 March 2005 - 10:47 PM

Hi,

Here some sample code so a TGridView accepts dragged files from the explorer. Steps are simple,

Add an TApplicationEvents vcl and connect it to the following OnEvent handler:

CODE
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;

 var Handled: Boolean);

var

 Buff              : array[0..MAX_PATH] of Char;

 Files,

   Count           : Word;

 fn                : string;

begin

 case Msg.message of

   WM_DropFiles:

     begin

       Handled := True;

       Files := DragQueryFile(Msg.wParam, $FFFFFFFF, nil, 0);

       for Count := 0 to Files - 1 do

         begin

           DragQueryFile(Msg.wParam, Count, @Buff, SizeOf(Buff) - 1);

           fn := PChar(@Buff);

           if (FileExists(fn)) then

             begin

/*process a file with filename fn here, beware mutliple files can be dropped too */

             end

           else

             MessageBeep(MB_ICONEXCLAMATION);

         end;

       DragFinish(Msg.wParam);

     end;

 else

   Handled := False;

 end;

end;



In the formcreate call

CODE
 DragAcceptFiles(GridView3.Handle, True);


found in the ShellApi unit (so include it).

Thats it!
G.W. van der Vegt

#2 Alfred

Alfred
  • Members
  • 17 posts
  • Gender:Male
  • Location:UK

Posted 20 May 2008 - 04:04 PM

And how does one determine WHERE the file was dropped - which row and which column?

In some other grid components it is done something like the following but I cannot see how to do it with NextGrid as I cannot find the method MouseToCell :

DragQueryPoint(DropHandle, DropPoint);

Grid1.DragDrop();

Grid1.MouseToCell(DropPoint.X, DropPoint.Y, ColumnDroppedOn, RowDroppedOn);

#3 Alfred

Alfred
  • Members
  • 17 posts
  • Gender:Male
  • Location:UK

Posted 20 May 2008 - 04:29 PM

I think I worked out by searching out other code on this forum. Just to save you time, here it is:

var
row1: Integer;
Point1: TPoint;
col1: TNxCustomColumn;
begin
GetCursorPos(Point1);
Point1 := NextGrid1.ScreenToClient(Point1);
row1 := NextGrid1.GetRowAtPos(Point1.X, Point1.Y);
col1 := NextGrid1.GetColumnAtPos(Point1);

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 20 May 2008 - 04:44 PM

Hello Alfred,

There is also GetCellAtPos function, maybe it may help you too?

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users