Jump to content
Sign in to follow this  
3ddark

StringGrid Row Move

Recommended Posts

Hello,
I want to move rows in StringGrid, a Delphi component. (Delphi 7, TStringGrid)

  • I fill the information in the stringrid as shown in the picture below.
  • I also adjust the stringgrid settings.
  • There is no problem with move to row
sGrid.FixedCols := 1;
sGrid.FixedRows := 1;
sGrid.Options := sGrid.Options + [goRowMoving];
 
procedure TFormX.sGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  gc: TGridCoord;
begin
  if Sender is TStringGrid then
  begin
    if TStringGridX(Sender).GridState in [gsRowMoving] then
    begin
      TStringGrid(Sender).MouseToCell(X, Y, gc.X, gc.Y);
      //get the row number of the first selected row
      FFromIndex := gc.Y;
    end;
  end;
end;

procedure TFormX.sGridMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
 gc: TGridCoord;
begin
  if Sender is TStringGrid then
  begin
    if TStringGridX(Sender).GridState in [gsRowMoving] then
    begin
      TStringGrid(Sender).MouseToCell(X, Y, gc.X, gc.Y);
      FToIndex := gc.Y;
    end;
  end;
end;

procedure TFormX.sGridMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
   gc: TGridCoord;
begin
  if Sender is TStringGrid then
  begin
    if TStringGridX(Sender).GridState in [gsRowMoving] then
    begin
      TStringGrid(Sender).MouseToCell(X, Y, gc.X, gc.Y);
      //here I know which lines you can go
      Caption := IntToStr(gc.X) + ':' + IntToStr(gc.Y);
    end;
  end;
end;

procedure TFormX.sGridRowMoved(Sender: TObject; FromIndex, ToIndex: Integer);
begin
  //it also says which row to move to which row.
  //How can I cancel this operation if it is not the row I want.
end;

From the attached picture,
Example 1-) I can move the A9 code on line 10 between lines 2 and 15. I want to prevent the move outside of these lines.
Example 2-) F code in line 20 can be moved to lines 1, 16, 23, 27. I will also move F1 and F2 lines under this F code. When the move starts, I find the lines where the move can be done (1,16,23,27)

what I really want it may seem like a complicated situation.
How do I cancel only the line move job?
How do I make it move over only the lines I want in the move?

Thanks in advance.

 

move_row.jpg.1e20f057faba61a2ec5ed2b96bb1acf3.jpg

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×