Mega Code Archive

 
Categories / Delphi / VCL
 

Move rows and columns of a StringGrid by code

Title: move rows and columns of a StringGrid by code? { The user can move rows and columns of a StringGrid with the mouse. Can it also be done by code? In the help for TCustomGrid you can see the methods MoveColumn and MoveRow, but they are hidden in TStringGrid. We can make them accessible again by subclassing TStringGrid and declaring these methods as public: Der Benutzer kann Zeilen und Spalten eines TStringgrids mit der Maus verschieben. Die Frage: Kann man sie auch automatisch verschieben ? Das TCustomGrid besitzt die Mehtoden MoveColumn und MoveRow, aber diese Methoden sind versteckt beim Stringgrid. Wir können sie zugänglich machen, indem wir eine Subklasse vom TStringGrid erstellen und diese Methoden als public deklarieren. } type TStringGridHack = class(TStringGrid) public procedure MoveColumn(FromIndex, ToIndex: Longint); procedure MoveRow(FromIndex, ToIndex: Longint); end; { The implementation of these methods simply consists of invoking the corresponding method of the ancestor: Die Implementierung dieser Methoden besteht nur darin, dass die Methoden des Vorfahren aufgerufen werden: } procedure TStringGridHack.MoveColumn(FromIndex, ToIndex: Integer); begin inherited; end; procedure TStringGridHack.MoveRow(FromIndex, ToIndex: Integer); begin inherited; end; // Example, Beispiel: procedure TForm1.Button1Click(Sender: TObject); begin TStringGridHack(StringGrid1).MoveColumn(1, 3); end;