Board index » delphi » Add row to a TQuery from a TdbGrid

Add row to a TQuery from a TdbGrid

Hello !

I have some question abouht add/del rows to a TQuery from a TDBGrid

What is the normal way of adding a row to a TQuery ?
When I add a row I have to close and open the TQuery to get the new row to
be visible in my grid.

At the same time the possition of the grid return to the start of the grid
 it dosent so in a TTable).
Is there a simpler way of do it, or do I have to fetch all of the rows from
the DB and then locate me to the new row ?

If I have 6 rows in a grid and row 3 is active and I want to add a new row
how can I go direct to row 7 and start editing.

Hope for some god advise !

?ivind

 

Re:Add row to a TQuery from a TdbGrid


"?ivind Wernersen" <werner...@kghspedition.com> schreef in bericht
news:8mnmth$99i$1@news.ost.eltele.no...

Quote
> Hello !

> I have some question abouht add/del rows to a TQuery from a TDBGrid

> What is the normal way of adding a row to a TQuery ?
> When I add a row I have to close and open the TQuery to get the new row to
> be visible in my grid.

Are you using a TQuery with RequestLive set to True or are you using an
TUpdateSQL UpdateObject with CachedUpdates set to True ?
Does switching to the other method help ?

Quote
> At the same time the possition of the grid return to the start of the grid
>  it dosent so in a TTable).
> Is there a simpler way of do it, or do I have to fetch all of the rows
from
> the DB and then locate me to the new row ?

This is a direct result of your first problem. Normally the new row would be
the current row after posting the record, but since this row isn't displayed
it can't be selected and Delphi selects the first record.

Quote
> If I have 6 rows in a grid and row 3 is active and I want to add a new row
> how can I go direct to row 7 and start editing.

You could call:
Query1.MoveBy(4);
Query1.Edit;

or, if you don't want to use code set dgAlwaysShowEditor in DBGrid1.Options.

Quote
> Hope for some god advise !

> ?ivind

Re:Add row to a TQuery from a TdbGrid


Hello,

I would advise you to set CashedUpdates property of TQuery to true and
assign UpdateObject to some TUpdateSQL. Read help for details. This style
gives you complete control over process of adding, deleting and updating
records.
If you Select records from one table you may set property RequestLive to
true (read others limitations on Select clause to be sure your request can
be declared "live"). This would allow you to work with TQuery as with
TTable.

Regards,
Sergei

Quote
> I have some question abouht add/del rows to a TQuery from a TDBGrid

> What is the normal way of adding a row to a TQuery ?
> When I add a row I have to close and open the TQuery to get the new row to
> be visible in my grid.

> At the same time the possition of the grid return to the start of the grid
>  it dosent so in a TTable).
> Is there a simpler way of do it, or do I have to fetch all of the rows
from
> the DB and then locate me to the new row ?

> If I have 6 rows in a grid and row 3 is active and I want to add a new row
> how can I go direct to row 7 and start editing.

> Hope for some god advise !

> ?ivind

Other Threads