Thema: Delphi DBgrid sortieren

Einzelnen Beitrag anzeigen

icebreaker

Registriert seit: 3. Okt 2006
27 Beiträge
 
#18

Re: DBgrid sortieren

  Alt 22. Jun 2007, 18:29
Delphi-Quellcode:
unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBClient, Grids, DBGrids, ExtCtrls, DBCtrls, DBTables,
  Mask, ADODB;

type
  TForm5 = class(TForm)
    Name: TLabel;
    Vorname: TLabel;
    Strasse: TLabel;
    hausnummer: TLabel;
    ClientDataSet1: TClientDataSet;
    ClientDataSet1Name: TStringField;
    ClientDataSet1Vorname: TStringField;
    ClientDataSet1Strae: TStringField;
    ClientDataSet1Hausnummer: TStringField;
    ClientDataSet1PLZ: TStringField;
    ClientDataSet1Ort: TStringField;
    ClientDataSet1Email: TStringField;
    DBNavigator1: TDBNavigator;
    DataSource1: TDataSource;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit7: TDBEdit;
    GroupBox1: TGroupBox;
    DBGrid1: TDBGrid;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Query1: TQuery;
    Query2: TQuery;


    procedure DBGrid1TitleClick(Column: TColumn);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);

   
  private
    { Private-Deklarationen }       
  public
      { Public-Deklarationen }
  end;
     type datensatz=record end;
var
  Form5: TForm5;
  sSortColumn: String;
  bSortOrder: Boolean;
 
implementation

uses Unit1, Unit4;
        
{$R *.dfm}


procedure TForm5.Button3Click(Sender: TObject);
begin
ClientDataSet1.SaveToFile('c:\Datenbank.da-guckst-du', dfXML);
end;

procedure TForm5.Button4Click(Sender: TObject);
begin
 ClientDataSet1.LoadFromFile('C:\Datenbank.da-guckst-du');
end;



procedure TForm5.DBGrid1TitleClick(Column: TColumn);

begin
 if Column.FieldName <> sSortColumn then
  begin
    sSortColumn := Column.FieldName;
  end
  else
  begin
    bSortOrder := not bSortOrder;
  end;
  query2.Close;
  if bSortOrder then
  begin
    query2.SQL.text := 'SELECT * FROM adressen.db ORDER BY ' + sSortColumn;
  end
  else
  begin
   query2.sql.text := 'SELECT * FROM adressen.db ORDER BY ' + sSortColumn + ' DESC';
  end;
  query2.Open;



end.
lass dir schmecken, bis gleich...
nebenbei:
  Mit Zitat antworten Zitat