Autor Beitrag
kiwicht
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Di 18.02.03 10:04 
hallöchen...

hab n "lustiges" problem bei der Abfrage meiner Tabelle, bezüglich der angeklickten spalte. das ganze läuft über die OnDblClick-Proc des Grids.
Und zwar passiert folgendes: wenn ich auf die erste Spalte clicke, klappts wunderbar, clicke ich auf die 2., gehts auch, clicke ich auf die dritte, erkennt er diese als 4. usw., hier ne übersicht:

1. spalte -> erkannt als 1.
2. spalte -> erkannt als 2.
3. spalte -> erkannt als 4.
4. spalte -> gar nicht erkannt
5. spalte -> erkannt als 3.
6. spalte -> gar nicht erkannt

hier der Code, der in meinem Prog auf mein Grid zugreift:

und zwar die init. der tabelle ansich, bei Form1.Create
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
with grArtmat do begin
Columns[0].FieldName := 'Text';
Columns[1].FieldName := 'Stueck';
Columns[2].FieldName := 'Listpreisv';
Columns[3].FieldName := 'Preisgr';
Columns[4].FieldName := 'Lagerort';
Columns[5].FieldName := 'Artiklnumr';
end;


und hier die abfrage, welches feld geklickt wurde, um dannzu sortieren:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
if grArtmat.SelectedField.Index = 1 then begin
qMatBestand.SQL.Clear;
qMatBestand.SQL.Add(SQLText);
label1.Caption := '1';
qMatBestand.SQL.Add(' ORDER BY text') end else

if grArtmat.SelectedField.Index = 2 then begin
qMatBestand.SQL.Clear;
qMatBestand.SQL.Add(SQLText);
label1.Caption := '2';
qMatBestand.SQL.Add(' ORDER BY stueck') end else

if grArtmat.SelectedField.Index = 3 then begin
qMatBestand.SQL.Clear;
qMatBestand.SQL.Add(SQLText);
label1.Caption := '3';
qMatBestand.SQL.Add(' ORDER BY Listpreisv') end else

if grArtmat.SelectedField.Index = 4 then begin
qMatBestand.SQL.Clear;
qMatBestand.SQL.Add(SQLText);
label1.Caption := '4';
qMatBestand.SQL.Add(' ORDER BY Preisgr') end else

if grArtmat.SelectedField.Index = 5 then begin
qMatBestand.SQL.Clear;
qMatBestand.SQL.Add(SQLText);
label1.Caption := '5';
qMatBestand.SQL.Add(' ORDER BY Lagerort') end else

if grArtmat.SelectedField.Index = 6 then begin
qMatBestand.SQL.Clear;
qMatBestand.SQL.Add(SQLText);
label1.Caption := '6';
qMatBestand.SQL.Add(' ORDER BY Artiklnumr') end;

qMatBestand.Open;


ich hab auch schon probiert, in den if-Abfragen bei null zu beginnen, klappt aber genauso wenig...

wär ganz nett wenn einer n lösungs-ansatz findet..

mfg kiwicht


Zuletzt bearbeitet von kiwicht am Do 20.02.03 09:51, insgesamt 1-mal bearbeitet
GuGl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 35



BeitragVerfasst: Mi 19.02.03 09:14 
Hallo kiwicht,

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.grArtmatDblClick(Sender: TObject);
var
   mystring : string;
begin
     label1.Caption := IntToStr(grArtmat.SelectedField.Index);
     mystring := SQLText + ' ORDER BY ' + grArtmat.SelectedField.FieldName;
     with qMatBestand do begin
          close;
          SQL.text := mystring;
          open;
     end;
end;


das hier funzt bei mir ohne Probleme, egal welche Spalte man klickt.
Sieht auch etwas besser aus als 6 x if-Abfrage

_________________
Gruß, GuGl
kiwicht Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1021

Win 7, MacOS
Delphi x, VBA, PHP, ...
BeitragVerfasst: Do 20.02.03 09:50 
jepp, getestet und für gut befunden! :D danke!

mfg
kiwicht