Board index » delphi » TQuery, DBGrid editing problem

TQuery, DBGrid editing problem

Hi,

I hope someone can help me with the following problem.

I have a TQuery, using local SQL on a Paradox table, connected to a DBGrid
via a TDataSource.
The TQuery's RequestLive property is set to TRUE, so that the data can be
edited, but  I want the user to be able to switch editing on or off by means
of a button.  I've tried using the ReadOnly property of the grid, and adding
or deleting dgEditing in the grid's Options, but neither seem to have any
effect.  Any ideas?

Ruth

 

Re:TQuery, DBGrid editing problem


DBgrid.ReadOnly has always stopped editing for me. Turning autoedit on
and off for the datasource will also control it, but the user
interaction will be a bit different. I usually use readonly for the
visual control since that doesn't let the user do anything, where
setting the datasource autoedit false will let the user change the
visible data, but not let it change the dataset.

Also, are you using cached updates? Might make a difference in
behavior.

HTH,
Dan

On Mon, 14 Apr 2003 22:39:14 +1000, "Ruth Buckner"

Quote
<drscientific-r...@powerup.com.au> wrote:
>Hi,

>I hope someone can help me with the following problem.

>I have a TQuery, using local SQL on a Paradox table, connected to a DBGrid
>via a TDataSource.
>The TQuery's RequestLive property is set to TRUE, so that the data can be
>edited, but  I want the user to be able to switch editing on or off by means
>of a button.  I've tried using the ReadOnly property of the grid, and adding
>or deleting dgEditing in the grid's Options, but neither seem to have any
>effect.  Any ideas?

>Ruth

Re:TQuery, DBGrid editing problem


<snip>
Dan <DanB at CMDCsystems dot com> wrote in message
news:3o8m9v4jt6acv9tcjq653focv64puj42pi@4ax.com...
Quote
> DBgrid.ReadOnly has always stopped editing for me.

<snip>

Thanks Dan.  All I had actually tried doing was inserting a record, which is
unaffected by ReadOnly.  I tried editing an existing record, and, you're
quite right, it does work!   That's what I get for working late at night :-)

Re:TQuery, DBGrid editing problem


Hi Ruth,

If you want to stop the user from inserting as well, then create a
BeforeInsert event on the TQuery and in it raise an exception. I'm not
completely sure, but the grid might in fact catch the exception so that the
user does not get the error message.

procedure  MyForm.MyQueryBeforeInsert(DataSet: TDataSet);
begin
  if MyGrid.ReadOnly then
    raise Exception.Create('Insert not allowed');
end;

Regards
John Bester

Quote
"Ruth Buckner" <drscientific-r...@powerup.com.au> wrote in message

news:S5Kma.70$Ka3.2541@nnrp1.ozemail.com.au...
Quote
> <snip>
> Dan <DanB at CMDCsystems dot com> wrote in message
> news:3o8m9v4jt6acv9tcjq653focv64puj42pi@4ax.com...
> > DBgrid.ReadOnly has always stopped editing for me.
> <snip>

> Thanks Dan.  All I had actually tried doing was inserting a record, which
is
> unaffected by ReadOnly.  I tried editing an existing record, and, you're
> quite right, it does work!   That's what I get for working late at night
:-)

Re:TQuery, DBGrid editing problem


Quote
John Bester <no...@nowhere.com> wrote in message

news:b7g1fd$mtq$1@ctb-nnrp2.saix.net...

Quote
> Hi Ruth,

> If you want to stop the user from inserting as well, then create a
> BeforeInsert event on the TQuery and in it raise an exception. I'm not
> completely sure, but the grid might in fact catch the exception so that
the
> user does not get the error message.

> procedure  MyForm.MyQueryBeforeInsert(DataSet: TDataSet);
> begin
>   if MyGrid.ReadOnly then
>     raise Exception.Create('Insert not allowed');
> end;

> Regards
> John Bester

Thanks John,

I looked at BeforeInsert, which I'd used in TTables before, but found that
the Abort method isn't available in TQuery and didn't think of raising an
exception.

As I'm using a TQuery descendent anyway, I just added an boolean AllowInsert
property which I set at the same time as setting ReadOnly on the grid, then
check on my insert button - the insert key and the down arrow on the
keyboard don't appear to work on a grid attached to a TQuery anyway.

Ruth

Other Threads