AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Stringgrid mit filter

Ein Thema von 5etH · begonnen am 20. Jul 2009 · letzter Beitrag vom 20. Jul 2009
Antwort Antwort
Benutzerbild von 5etH
5etH

Registriert seit: 4. Mär 2008
Ort: Giessen
217 Beiträge
 
Delphi 2007 Professional
 
#1

Re: Stringgrid mit filter

  Alt 20. Jul 2009, 11:13
okay habe es geschaft für den, den es interessiert hier meine lösung:

Delphi-Quellcode:
procedure SetFilter(ACol:Integer;Exp:string);
var
  I,Counter:Integer;
begin
  FilterList:=TStringList.Create;
  with form1.stringGrid1 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;

procedure RestoreFilter;
var
  I:Integer;
begin
  with form1.Stringgrid1 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;



procedure TForm1.Button3Click(Sender: TObject); //Filtern
var
  I: Integer;
  vorhanden : Boolean;
begin
vorhanden := false;
button3.Enabled := false;
edit2.Enabled := false;
combobox2.Enabled := false;
button7.Enabled := true;
for I := 1 to stringgrid1.RowCount - 1 do
begin
  if stringgrid1.Cells[combobox2.ItemIndex+1,i] = edit2.text then
    begin
      vorhanden := true;
    end;
end;
if vorhanden then
begin
SetFilter(combobox2.ItemIndex+1,edit2.text);
end
else
begin
  showmessage('No records with '+edit2.Text+' where found!');
  button3.Enabled := true;
  edit2.Enabled := true;
  combobox2.Enabled := true;
  button7.Enabled := false;
end;

end;


procedure TForm1.Button7Click(Sender: TObject); //Restore
var
Dynarray : array of array of String;
I : Integer;
  X: Integer;
  Y: Integer;
begin
button3.Enabled := true;
edit2.Enabled := true;
combobox2.Enabled := true;
button7.Enabled := false;
setlength(dynarray,5);
  for I := 0 to 5 - 1 do
    begin
      setlength(dynarray[i],stringgrid1.rowCount);
    end;
  for X := 0 to Stringgrid1.ColCount -1do
    begin
      for Y := 0 to stringgrid1.rowCount -1 do
        begin
          dynarray[x,y] := stringgrid1.Cells[x,y];
        end;
    end;

RestoreFilter;
for X := 0 to Stringgrid1.rowCount - 1 do
  begin
    for Y := 0 to length(dynarray[0]) -1 do
      begin
        if stringgrid1.Cells[0,X] = dynarray[0,Y] then
        begin
          for I := 0 to 5 - 1 do
            begin
              stringgrid1.Cells[I,X] := dynarray[I,y];
            end;
        end;
      end;
  end;
end;
vielen Dank nochmal
schöne Grße
5etH
Manuel
Lieber heimlich schlau als unheimlich dumm
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz