Autor Beitrag
janis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


D7 Prof
BeitragVerfasst: Sa 11.09.04 21:03 
Hallo ich habe folgendes Problem

wie kann ich bei einem DBGRID und beim DBNAVIGATOR mittels Code die DATASOURCE wechseln, damit ich die Tabellen wechseln kann, welche in einem Formular angezeigt werden
Vielen Dank für eine Antwort
Janis
:gruebel:
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Sa 11.09.04 23:04 
hallo janis!

du brauchst nur zu überlegen, das du zur design-time in die eigenschaft 'datasource' des DBGrid und DBNav einträgst. ein wechsel zur laufzeit ist auch nichts anderes.

mfg, stefan
Johannes Maier
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 173

Win XP
D7 Prof
BeitragVerfasst: So 12.09.04 08:02 
Jep die Eigenschaft heißt genau wie im ObjektInspektor ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button1Click(Sender: TObject);
begin
  DBGRID.DataSource := NewSource; //irgendein anderes
  DBNAVIGATOR.DataSource := NewSource; //das gleiche
end;

_________________
MfG
Johannes ehem. jbmaier
janis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


D7 Prof
BeitragVerfasst: So 12.09.04 12:40 
Vielen Dank für die Antwort,
ich habe es gleich probiert und konnte das Programm auch Compilieren.
Leider wenn ich das Programm ausführe und das Formular auswähle, wo die DBGRID ist, bekommen ich eine
Fehlermeldung Zugriffesverletzung
Janis
:shock:
djmasi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Win XP Prof. Tablet PC Edition 2005
D7 Enterprise
BeitragVerfasst: So 12.09.04 13:16 
Vielleicht könntest Du mal einen Teil von Deinem Code posten? Weil habs gerade ausprobiert und bei mir geht es wunderbar (2 TTable, 2 DataSource).
janis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


D7 Prof
BeitragVerfasst: So 12.09.04 14:30 
Dann poste ich mal einen Teil

If FrmMain.PrueferMain=('Neue Nummer') Then
Begin
Frm_Unternummern.DBGrid_Unternummern.DataSource:=Dtm_Datenbank.Dts_TempUnternummre;
Frm_Unternummern.DBNavigatorUnternummern.DataSource:=Dtm_Datenbank.Dts_TempUnternummre;
End;

Filternummer2:='';
Filternummer2:=FrmErfassung.Filerternummer1;
Filternummer2:=(IntToStr(Dtm_Datenbank.ADOTbl_DatenID.Value));
Filternummer2:='Laufnummer_id='+Filternummer2;
with Dtm_Datenbank.ADOTbl_TempUnternummer do begin
Filtered := False;
Filter := Filternummer2;
Filtered := True;
End;

Gruss Janis
:shock:
djmasi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Win XP Prof. Tablet PC Edition 2005
D7 Enterprise
BeitragVerfasst: So 12.09.04 17:32 
Benutze doch bitte die Delphi-Tags und schreib ein paar Kommentare dazu. Das fällt dann leichter. Auch was für Komponenten du genau nimmst :wink:

Bsp:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure irgendwas;
begin
  //macht dies
  Anweisung1;
  //macht jenes
  Anweisung2;
end;
djmasi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Win XP Prof. Tablet PC Edition 2005
D7 Enterprise
BeitragVerfasst: So 12.09.04 17:52 
Ich denke mal Dein Fehler liegt hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Filternummer2:=''; //überflüssig
Filternummer2:=FrmErfassung.Filerternummer1; //warum das, wenn du gleich wieder was anderes zuweist?
Filternummer2:=(IntToStr(Dtm_Datenbank.ADOTbl_DatenID.Value));
Filternummer2:='Laufnummer_id='+Filternummer2;
janis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


D7 Prof
BeitragVerfasst: So 12.09.04 19:16 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
If FrmMain.PrueferMain=('Neue Nummer') Then
Begin
// wenn es sich um eine Neue Numme handelt, soll die DBGRID ; DBNAVIGATOR die Tabelle TEmpUnternummer verwenden
    Frm_Unternummern.DBGrid_Unternummern.DataSource:=Dtm_Datenbank.Dts_TempUnternummer;
    Frm_Unternummern.DBNavigatorUnternummern.DataSource:=Dtm_Datenbank.Dts_TempUnternummer;
End;  // End IF Neue Nummer


der Filter funktioniert, das habe ich ausprobiert
Danke Janis