3ddark 3 Posted March 17, 2020 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. Share this post Link to post