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

97 Visitors Online


 
...Insert/Delete a row in a TStringGrid?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (37):  
     


// For this tip you need a StringGrid1 and a Button1.
// Für diesen Tip braucht man ein StringGrid1 und einen Button1.


{...}
type
  
TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    
{...}
  
public
    
{...}
  
end;

type
  
TStringGridHack = class(TStringGrid)
  protected
    procedure 
DeleteRow(ARow: Longint); reintroduce;
    procedure InsertRow(ARow: Longint);
  end;

var
  
Form1: TForm1;

implementation

{$R *.DFM}

procedure TStringGridHack.DeleteRow(ARow: Longint);
var
  
GemRow: Integer;
begin
  
GemRow := Row;
  if RowCount > FixedRows + 1 then
    inherited 
DeleteRow(ARow)
  else
    
Rows[ARow].Clear;
  if GemRow < RowCount then Row := GemRow;
end;

procedure TStringGridHack.InsertRow(ARow: Longint);
var
  
GemRow: Integer;
begin
  
GemRow := Row;
  while ARow < FixedRows do Inc(ARow);
  RowCount := RowCount + 1;
  MoveRow(RowCount - 1, ARow);
  Row := GemRow;
  Rows[Row].Clear;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  
// Insert Row, Zeile hinzufügen
  
TStringGridHack(StringGrid1).InsertRow(1);
  // Remove Row, Zeile entfernen
  
TStringGridHack(StringGrid1).DeleteRow(2);
end;

end.


 

Rate this tip:

poor
very good


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