Board index » delphi » Drag Drop and with a column of a TStringGrid

Drag Drop and with a column of a TStringGrid

Hello,

How can one displace a column of a TStringGrid on another component?

thank you for your help.

Olivier

 

Re:Drag Drop and with a column of a TStringGrid


In article <ahv4hk$sg...@wanadoo.fr>, "Olivier" <mansooliv...@wanadoo.fr>
writes:

Quote
>How can one displace a column of a TStringGrid on another component?

You have to expose the MoveColumn method of the TStringGrid by typecasting it
to any convenient descendant of the TStringGrid. Then to drag (but only when
starting and ending in the header row) ...

type
  TMoveColGrid = class(TStringGrid); // for exposing the protected MoveColumn
method

var
  StartCol : integer;

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
               Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
{starts dragging}
var
  ACol, ARow : integer;
begin
  with StringGrid1 do begin
    MouseToCell(X, Y, ACol, ARow);  // gets column and row
    if ARow = 0 then begin  // drags only in row 1
      StartCol := ACol; // stores starting column
      BeginDrag(false); // false starts drag when mouse has moved 5 pixels
    end;
  end; {with StringGrid1}
end;

procedure TForm1.StringGrid1DragOver(Sender, Source: TObject; X,
               Y: Integer; State: TDragState; var Accept: Boolean);
{displays drag cursor as you drag over stringgrid}
begin
  Accept := (Sender = StringGrid1);
end;

procedure TForm1.StringGrid1DragDrop(Sender, Source: TObject;
                                     X, Y: Integer);
{moves column when you drop}
var
  ACol, ARow : integer;
begin
  with StringGrid1 do begin
    MouseToCell(X, Y, ACol, ARow);
    if ARow = 0 then
      TMoveColGrid(StringGrid1).MoveColumn(StartCol, ACol); // note typecast
  end; {with StringGrid1}
end;

Alan Lloyd
alangll...@aol.com

Re:Drag Drop and with a column of a TStringGrid


Thank you for your answer it is precisely for what I looked!

Olivier

"AlanGLLoyd" <alangll...@aol.com> a crit dans le message de news:
20020728020630.14565.00000...@mb-fq.aol.com...

Quote
> In article <ahv4hk$sg...@wanadoo.fr>, "Olivier" <mansooliv...@wanadoo.fr>
> writes:

> >How can one displace a column of a TStringGrid on another component?

> You have to expose the MoveColumn method of the TStringGrid by typecasting
it
> to any convenient descendant of the TStringGrid. Then to drag (but only
when
> starting and ending in the header row) ...

> type
>   TMoveColGrid = class(TStringGrid); // for exposing the protected
MoveColumn
> method

> var
>   StartCol : integer;

> procedure TForm1.StringGrid1MouseDown(Sender: TObject;
>                Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
> {starts dragging}
> var
>   ACol, ARow : integer;
> begin
>   with StringGrid1 do begin
>     MouseToCell(X, Y, ACol, ARow);  // gets column and row
>     if ARow = 0 then begin  // drags only in row 1
>       StartCol := ACol; // stores starting column
>       BeginDrag(false); // false starts drag when mouse has moved 5 pixels
>     end;
>   end; {with StringGrid1}
> end;

> procedure TForm1.StringGrid1DragOver(Sender, Source: TObject; X,
>                Y: Integer; State: TDragState; var Accept: Boolean);
> {displays drag cursor as you drag over stringgrid}
> begin
>   Accept := (Sender = StringGrid1);
> end;

> procedure TForm1.StringGrid1DragDrop(Sender, Source: TObject;
>                                      X, Y: Integer);
> {moves column when you drop}
> var
>   ACol, ARow : integer;
> begin
>   with StringGrid1 do begin
>     MouseToCell(X, Y, ACol, ARow);
>     if ARow = 0 then
>       TMoveColGrid(StringGrid1).MoveColumn(StartCol, ACol); // note
typecast
>   end; {with StringGrid1}
> end;

> Alan Lloyd
> alangll...@aol.com

Other Threads