DragToGridForm.pas
资源名称:delphi.rar [点击查看]
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:1k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit DragToGridForm;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Db, DBTables, Grids, DBGrids;
- type
- TFormDrag = class(TForm)
- DBGrid1: TDBGrid;
- DataSource1: TDataSource;
- Table1: TTable;
- LabelDrag: TLabel;
- EditDrag: TEdit;
- procedure DBGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
- procedure DBGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
- State: TDragState; var Accept: Boolean);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FormDrag: TFormDrag;
- implementation
- {$R *.DFM}
- type
- TDBGHack = class (TDbGrid)
- end;
- procedure TFormDrag.DBGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
- var
- gc: TGridCoord;
- begin
- gc := TDBGHack(DbGrid1).MouseCoord (x, y);
- if (gc.y > 0) and (gc.x > 0) then
- begin
- DbGrid1.DataSource.DataSet.MoveBy (gc.y - TDBGHack(DbGrid1).Row);
- DbGrid1.DataSource.DataSet.Edit;
- DBGrid1.Columns.Items [gc.X - 1].Field.AsString := EditDrag.Text;
- end;
- DBGrid1.SetFocus;
- end;
- procedure TFormDrag.DBGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
- State: TDragState; var Accept: Boolean);
- begin
- Accept := (Source = LabelDrag);
- end;
- end.