Thema: Delphi Stringgrid mit filter

Einzelnen Beitrag anzeigen

Benutzerbild von 5etH
5etH

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

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