was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

40 Visitors Online


 
...ein StringGrid mit einer Filter-Funktion erweitern?
Autor: Schatzl Reinhard
[ Tip ausdrucken ]  

Tip Bewertung (9):  
     


// Filter Liste zum sichern des Gridinhalt
// save the original content
var
  
FilterList : TStringList;

// Filter setzen
// set the filter
procedure TForm1.SetFilter(ACol:Integer;Exp:String);
var
  
I,Counter:Integer;
begin
  
FilterList:=TStringList.Create;
  With Grid do
  begin
    
//Filterliste mit Gridinhalt füllen
    
For I := FixedRows To RowCount - 1 Do
      
FilterList.Add(Rows[I].Text);

    //Grid filtern
    
Counter:=FixedRows;
    For I := FixedRows To RowCount - 1 Do
    Begin
      If 
Cells[ACol,I] <> Exp Then
      Begin
         
Rows[I].Clear;
      end
      Else
      begin
         If 
Counter <> I Then
         Begin
           
Rows[Counter].Assign(Rows[I]);
           Rows[I].Clear;
         End;
         Inc(Counter);
      End;
    End;
    RowCount:=Counter;
  End;
end;

// Gridinhalt wiederherstellen
// restore the original content
procedure TForm1.RestoreFilter;
var
  
I:Integer;
begin
  With 
Grid do
  begin
    
RowCount:=FixedRows+FilterList.Count;
    For I:=0 To FilterList.Count - 1 Do
        
Rows[FixedRows+I].Text := FilterList.Strings[I];
  End;
  FilterList.Free;
end;


//Example
procedure TForm1.BtnSetFilterClick(Sender: TObject);
begin
  
//Grid nach Zellinhalt der markierten Zelle filtern
  
SetFilter(Grid.Col,Grid.Cells[Grid.Col,Grid.Row]);
end;

procedure TForm1.BtnRestoreFilterClick(Sender: TObject);
begin
  
RestoreFilter;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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