whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

34 Visitors Online


 
...move rows and columns of a StringGrid by code?
Autor: P. Below
Homepage: http://www.teamb.com
[ Print tip ]  

Tip Rating (13):  
     


{
  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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners