Autor Beitrag
DelphiMan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: So 09.02.03 15:08 
Hallo zusammen!
Wie kann man ein DBGrid, welches durch eine TTable Komponente gesteuert wird, nach einer bestimmten Spalte sortieren?
Danke im voraus!
MfG
DelphiMan
M. Raab
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 334
Erhaltene Danke: 1

WIN 7
Delphi XE
BeitragVerfasst: So 09.02.03 15:18 
Hallöchen,

dazu mußt Du einen Index anlegen und den kannst Du dann absteigend/steigend machen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Table1.Active := False;

Table1.Exclusive := True;
{ Aktuell verfügbare Indizes ermitteln }
Table1.IndexDefs.Update;
{ Index suchen, der Customer Number ('CustNo') und Order Number ('OrderNo') kombiniert}
for I := 0 to Table1.IndexDefs.Count - 1 do
  if Table1.IndexDefs.Items[I].Fields = 'CustNo;OrderNo' then
   { diesen Index zum aktuellen machen }
    Table1.IndexName := Table1.IndexDefs.Items[I].Name;
Table1.Exclusive := False;

Table1.Active := True;



Gruss


Markus
Lake
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78


D6 prof., Delphi 10.2 Tokyo
BeitragVerfasst: So 09.02.03 15:28 
Hallo,

ich löse das Probelm über mehrere Indexe und das Ereignis OnTitleClick.
Zur Laufzeit wird durch einen Klick auf die Spaltenüberschrift der Index umschaltet.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  sColumn : String;
begin
  sColumn := Column.FieldName; // Spaltennamen ermitteln
  if UpperCase(sColumn) = 'SPALTE1' then
      table1.IndexName := 'IndexName1';
  if UpperCase(sColumn) = 'SPALTE2' then
      table1.IndexName := 'IndexName2';
 // und so weiter.
end;

mfg
Lake
DelphiMan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: So 09.02.03 16:05 
Titel: Indize?
Wie leg ich Indize richtig an - was bringt das? Kenn mich damit leider nicht so gut aus. Ich benötige eine Tabelle mit einer Spalte 'id' welche auto_increment sein soll und mit anderen spalten wie kundennr, name, telefon usw. Wäre toll wenn ihr mir sagen könntet, wie ich die struktur (in groben umrissen) dafür wählen muss, damit jede spalte zur laufzeit sortiert werden kann (aufsteigend und absteigen).
Vielen Dank im Voraus!
MfG
DelphiMan
Lake
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 78


D6 prof., Delphi 10.2 Tokyo
BeitragVerfasst: So 09.02.03 18:53 
Entweder Du erstellst die Indexe mit der Datenbankoberfläche oder zur Laufzeit beim erstellen der Tabelle siehe nachfolgenden Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
with IndexDefs do
begin
    clear;
    // Prim-Index
    add('pIndexName','Feld1;Feld2;Feld3',[ixPrimary,ixUnique]);
    // Sec-Indexe
    add('sIndex1','Feld2;Feld4',[ixDescending]);
    add('sIndex2','Feld1;Feld3',[ixDescending]);
    add('sIndex3','Feld3;Feld4;Feld5',[]);
end;
createTable;

mfg
Lake
DelphiMan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: So 09.02.03 20:23 
Titel: danke
s.o.
alexschultze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 317



BeitragVerfasst: Di 20.05.03 21:19 
Titel: ohne indexe?
nur theoretisch, würde es auch ohne Indexe gehen? Das ist bissl blöd...

_________________
Von allen Dingen die ich verloren habe trauere ich meinem Verstand am meisten nach.