Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Drag and drop

Posted on 1998-02-12
4
Medium Priority
?
249 Views
Last Modified: 2010-05-18
I am trying to implement drag and drop between DBGrids on two seperate forms but as yet I haven't managed it. Can someone help me?
0
Comment
Question by:alanward
[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
4 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1359065
do the two forms belong to the same process (i.e. the same application instance) ? If not, you will have to implement OLE drag and drop to transfer data between process boundaries.

Slash/d003303
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359066
Here is an example :

Push Fill grid button; (bitbutton1)
Push Show other form button (button1)

Push mouse button on grid and drag to other form

Regards, Zif.

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    BitBtn1: TBitBtn;
    Button1: TButton;
    procedure BitBtn1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 Form2.Show;
end;

procedure TForm1.Button1Click(Sender: TObject);

var i,j : integer;
begin
 for i := 1 to 10 do
  for j := 1 to 10 do
   StringGrid1.Cells[i,j] := 'Cell '+IntToStr(i)+IntToStr(j);
end;

end.

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids;

type
  TForm2 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure StringGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.DFM}

procedure TForm2.StringGrid1DragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  if Source is TStringGrid then
    Accept := True;end;

procedure TForm2.StringGrid1DragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  if Source is TStringGrid then
   begin    StringGrid1.Cells[Form1.StringGrid1.Col,Form1.StringGrid1.Row] :=      Form1.StringGrid1.Cells[Form1.StringGrid1.Col,Form1.StringGrid1.Row];   end;
end;

end.

Questions? Just ask.

0
 

Author Comment

by:alanward
ID: 1359067
ZifNab's answer involved String grids my question was specifically about DBGrids, I don't know if the same code will work for both.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 300 total points
ID: 1359068
sure it works with dbgrids! Only the dragdrop is different :
With this example you can see that the dbgrid in form2 will accept from dbgrid1.

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    DBGrid1: TDBGrid;
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
 Form2.Show;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
 dbgrid1.dragmode :=  dmAutomatic;
end;

end.

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids;

type
  TForm2 = class(TForm)
    DBGrid1: TDBGrid;
    procedure DBGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.DBGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
if Source is TDBGrid then
            Accept := True;
end;


end.

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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