Board index » delphi » DBNavigator

DBNavigator

Hello,

I am using a DateTimePicker on a form which also contains a DBNavigator.

One of the fields in the underlying database is populated with the date
in the
DateTimePicker on pressing the post key of the DBNavigator.This part
works OK.

If however I amend the code such that I am also able to Navigate through

my database using the DBNavigator showing the changes appearing for each

record including the changing of the date in the DateTimePicker..then I
am
unable to add new records.

I think that the reason is because when I press the button to add a new
record
that the DBNavigator moves to the next  blank field and this probably
causes the problem for the DateTimePicker as it would have no value

Is there any way round this or is there a way of writting code which
access's
the individual keys of the DBNavigator?

Thanks

Kevin

 

Re:DBNavigator


Use:

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  if not Assigned(Field) then
    if (Sender as TDataSource).State in [dsBrowse, dsEdit] then
      DateTimePicker.Date := DataSet.FieldByName('Date').AsDateTime
    else
      DateTimePicker.Date := Now;
end;

procedure TForm1.Table1BeforePost(DataSet: TDataSet);
begin
  DataSet.FieldByName('Date').AsDateTime := DateTimePicker.Date;
end;

"Kevin" <kevin.s.robin...@bt.com> schreef in bericht
news:39A38A0A.4F7DAACE@bt.com...

Quote
> Hello,

> I am using a DateTimePicker on a form which also contains a DBNavigator.

> One of the fields in the underlying database is populated with the date
> in the
> DateTimePicker on pressing the post key of the DBNavigator.This part
> works OK.

> If however I amend the code such that I am also able to Navigate through

> my database using the DBNavigator showing the changes appearing for each

> record including the changing of the date in the DateTimePicker..then I
> am
> unable to add new records.

> I think that the reason is because when I press the button to add a new
> record
> that the DBNavigator moves to the next  blank field and this probably
> causes the problem for the DateTimePicker as it would have no value

> Is there any way round this or is there a way of writting code which
> access's
> the individual keys of the DBNavigator?

> Thanks

> Kevin

Other Threads