DataGrid nightmare 
Author Message
 DataGrid nightmare

I've been hassling with this DataGrid (V6 sp5) problem for days now!  There
must be a better way.

I have a grid which allows users to insert new rows into a SQL Server table.
The table actually has the visible fields in the grid, as well as a field
which must be given a value programmatically.  I've tried various
combinations if sticking the field in a hidden column in the grid, and
deleting the column from the grid altogether (but still in the recordset).
I have tried using the grid's OnAddNew event to stuff the value into the
hidden field (tried both stuffing it into the hidden column, or directly
into the recordset).  Either way I do this, the recordset decides that it
has been changed., and wants to update if the user moves off of it.  (which
is not appropriate when the user didn't type anything).

I have not been able to figure out an event hook to prevent this. There are
scads of events fired from the DataGrid, but none of them seem to be in the
right place at the right time to do something like .CancelUpdate.

Can someone please suggest a way to do this?  Am I asking too much from the
DataGrid control?

Thanks very much for any guidance here.



Mon, 08 Sep 2003 16:29:01 GMT  
 DataGrid nightmare

Quote:
>right place at the right time to do something like .CancelUpdate.

>Can someone please suggest a way to do this?  Am I asking too much from the
>DataGrid control?
----Original Message-----

>right place at the right time to do something like .CancelUpdate.

I've had a similar problem , in my programming.
There should be a way to cancelupdate but I don't find it.
So, if You have received any good advise,please let me know!

-remove the NOSPAM from my e-mail address.



Mon, 08 Sep 2003 18:53:30 GMT  
 DataGrid nightmare
If you put a value into a 'hidden column' or 'directly into the recordset',
then the recordset *has* been changed.
Anyway... are you using an ado data control?
If so, you can use the WillMove event of the data control to check data and
issue a CancelUpdate.

-Steven Elliott


Quote:
> I've been hassling with this DataGrid (V6 sp5) problem for days now!
There
> must be a better way.

> I have a grid which allows users to insert new rows into a SQL Server
table.
> The table actually has the visible fields in the grid, as well as a field
> which must be given a value programmatically.  I've tried various
> combinations if sticking the field in a hidden column in the grid, and
> deleting the column from the grid altogether (but still in the recordset).
> I have tried using the grid's OnAddNew event to stuff the value into the
> hidden field (tried both stuffing it into the hidden column, or directly
> into the recordset).  Either way I do this, the recordset decides that it
> has been changed., and wants to update if the user moves off of it.
(which
> is not appropriate when the user didn't type anything).

> I have not been able to figure out an event hook to prevent this. There
are
> scads of events fired from the DataGrid, but none of them seem to be in
the
> right place at the right time to do something like .CancelUpdate.

> Can someone please suggest a way to do this?  Am I asking too much from
the
> DataGrid control?

> Thanks very much for any guidance here.



Tue, 09 Sep 2003 10:31:35 GMT  
 DataGrid nightmare
It seems that the update is done before the WillMove event.


Quote:
> If you put a value into a 'hidden column' or 'directly into the
recordset',
> then the recordset *has* been changed.
> Anyway... are you using an ado data control?
> If so, you can use the WillMove event of the data control to check data
and
> issue a CancelUpdate.

> -Steven Elliott



> > I've been hassling with this DataGrid (V6 sp5) problem for days now!
> There
> > must be a better way.

> > I have a grid which allows users to insert new rows into a SQL Server
> table.
> > The table actually has the visible fields in the grid, as well as a
field
> > which must be given a value programmatically.  I've tried various
> > combinations if sticking the field in a hidden column in the grid, and
> > deleting the column from the grid altogether (but still in the
recordset).
> > I have tried using the grid's OnAddNew event to stuff the value into the
> > hidden field (tried both stuffing it into the hidden column, or directly
> > into the recordset).  Either way I do this, the recordset decides that
it
> > has been changed., and wants to update if the user moves off of it.
> (which
> > is not appropriate when the user didn't type anything).

> > I have not been able to figure out an event hook to prevent this. There
> are
> > scads of events fired from the DataGrid, but none of them seem to be in
> the
> > right place at the right time to do something like .CancelUpdate.

> > Can someone please suggest a way to do this?  Am I asking too much from
> the
> > DataGrid control?

> > Thanks very much for any guidance here.



Tue, 09 Sep 2003 11:09:30 GMT  
 DataGrid nightmare
Should I be looking for a 3rd party Grid control?


Quote:
> I've been hassling with this DataGrid (V6 sp5) problem for days now!
There
> must be a better way.

> I have a grid which allows users to insert new rows into a SQL Server
table.
> The table actually has the visible fields in the grid, as well as a field
> which must be given a value programmatically.  I've tried various
> combinations if sticking the field in a hidden column in the grid, and
> deleting the column from the grid altogether (but still in the recordset).
> I have tried using the grid's OnAddNew event to stuff the value into the
> hidden field (tried both stuffing it into the hidden column, or directly
> into the recordset).  Either way I do this, the recordset decides that it
> has been changed., and wants to update if the user moves off of it.
(which
> is not appropriate when the user didn't type anything).

> I have not been able to figure out an event hook to prevent this. There
are
> scads of events fired from the DataGrid, but none of them seem to be in
the
> right place at the right time to do something like .CancelUpdate.

> Can someone please suggest a way to do this?  Am I asking too much from
the
> DataGrid control?

> Thanks very much for any guidance here.



Tue, 09 Sep 2003 14:01:06 GMT  
 DataGrid nightmare
I don't think the fault is with the grid. Something else is affecting it in
your code, most likely.

-Steven Elliott


Quote:
> Should I be looking for a 3rd party Grid control?



> > I've been hassling with this DataGrid (V6 sp5) problem for days now!
> There
> > must be a better way.

> > I have a grid which allows users to insert new rows into a SQL Server
> table.
> > The table actually has the visible fields in the grid, as well as a
field
> > which must be given a value programmatically.  I've tried various
> > combinations if sticking the field in a hidden column in the grid, and
> > deleting the column from the grid altogether (but still in the
recordset).
> > I have tried using the grid's OnAddNew event to stuff the value into the
> > hidden field (tried both stuffing it into the hidden column, or directly
> > into the recordset).  Either way I do this, the recordset decides that
it
> > has been changed., and wants to update if the user moves off of it.
> (which
> > is not appropriate when the user didn't type anything).

> > I have not been able to figure out an event hook to prevent this. There
> are
> > scads of events fired from the DataGrid, but none of them seem to be in
> the
> > right place at the right time to do something like .CancelUpdate.

> > Can someone please suggest a way to do this?  Am I asking too much from
> the
> > DataGrid control?

> > Thanks very much for any guidance here.



Wed, 10 Sep 2003 17:22:18 GMT  
 DataGrid nightmare
When you do the addnew event, check the add new mode.  If it's current, the
user hasn't typed anything, if it's pending then they have.  Try only
putting the information in the row after the the mode becomes pending.     I
haven't had any problems getting the information into the row.  It's getting
it to update right away that I'm having problems.

Suzette


Quote:
> I've been hassling with this DataGrid (V6 sp5) problem for days now!
There
> must be a better way.

> I have a grid which allows users to insert new rows into a SQL Server
table.
> The table actually has the visible fields in the grid, as well as a field
> which must be given a value programmatically.  I've tried various
> combinations if sticking the field in a hidden column in the grid, and
> deleting the column from the grid altogether (but still in the recordset).
> I have tried using the grid's OnAddNew event to stuff the value into the
> hidden field (tried both stuffing it into the hidden column, or directly
> into the recordset).  Either way I do this, the recordset decides that it
> has been changed., and wants to update if the user moves off of it.
(which
> is not appropriate when the user didn't type anything).

> I have not been able to figure out an event hook to prevent this. There
are
> scads of events fired from the DataGrid, but none of them seem to be in
the
> right place at the right time to do something like .CancelUpdate.

> Can someone please suggest a way to do this?  Am I asking too much from
the
> DataGrid control?

> Thanks very much for any guidance here.



Thu, 11 Sep 2003 10:21:16 GMT  
 DataGrid nightmare
Thanks for the suggestion.

I'm finding that addnew event is only called once -- before the user types.
The dataGrid.addNewMode is indeed dbgAddNewCurrent.  But it never gets
called again with Mode= dbgAddNewPending.  I have been able to catch this
value in places like recordset_willChangeRecord, but I can't seem to update
the recordset there.  I get an error message about re-entrant events.

[quick experiment]

OK, I've tried the same thing with client side cursor (static cursor).  Now
I can update the recordset within the recordset_WillChangeRecord event.  So,
I seem to now have the solution:

Delcare recordset with "With Events" (or use a recordset control).  Create a
recordset_WillChangeRecord handler, that checks for "adReason =
adRsnUpdate".  Then, if precordset.EditMode = adEditAdd, set the hidden
field in the recordset.  I still have a problem (unrelated I think) when the
user clicks of the datagrid to somewhere else on the form, which leaves the
recordset with changes pending.  I think I can solve that with a LostFocus
event handler though.  Or, in code:

Dim WithEvents rs As ADODB.Recordset

Private Sub rs_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum,
ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset
As ADODB.Recordset)
' Handle case where user has inserted a new row into the grid.  Must fill in
the
' HiddenField before the table can be updated.

    If adReason = adRsnUpdate Then    ' Only care when recordset is about to
update:
'    stuff in the hidden field now:
        If pRecordset.EditMode = adEditAdd Then pRecordset!HiddenField =
hiddenvalue
    Else
        adStatus = adStatusUnwantedEvent    ' Don't bother me with this one
again.
    End If
End Sub

I was sure I had a good reason for using a server side cursor.  If this is
the case, can anyone verify/explain why this would not work with a server
side cursor (keyset type)?

Thanks again to all of those who responded (and those who have not yet
responded!)


Quote:
> When you do the addnew event, check the add new mode.  If it's current,
the
> user hasn't typed anything, if it's pending then they have.  Try only
> putting the information in the row after the the mode becomes pending.
I
> haven't had any problems getting the information into the row.  It's
getting
> it to update right away that I'm having problems.

> Suzette



> > I've been hassling with this DataGrid (V6 sp5) problem for days now!
> There
> > must be a better way.

> > I have a grid which allows users to insert new rows into a SQL Server
> table.
> > The table actually has the visible fields in the grid, as well as a
field
> > which must be given a value programmatically.  I've tried various
> > combinations if sticking the field in a hidden column in the grid, and
> > deleting the column from the grid altogether (but still in the
recordset).
> > I have tried using the grid's OnAddNew event to stuff the value into the
> > hidden field (tried both stuffing it into the hidden column, or directly
> > into the recordset).  Either way I do this, the recordset decides that
it
> > has been changed., and wants to update if the user moves off of it.
> (which
> > is not appropriate when the user didn't type anything).

> > I have not been able to figure out an event hook to prevent this. There
> are
> > scads of events fired from the DataGrid, but none of them seem to be in
> the
> > right place at the right time to do something like .CancelUpdate.

> > Can someone please suggest a way to do this?  Am I asking too much from
> the
> > DataGrid control?

> > Thanks very much for any guidance here.



Fri, 12 Sep 2003 12:01:56 GMT  
 DataGrid nightmare
I may be miss-understanding your problem but here goes...
Im using componentOne's TrueDBGrid control which is as I understand it is what
the microsoft version is but with all the features turned on... anyway - it
appears that the Microsoft version has the same method you need...

try the _BeforeColUpdate event .  Test the column index if you need to see
which column is being changed etc, do any field validation or computing you
need to then either do a grid .update or set Cancel = True
you may need to do something with the befor col Edit event to save the prior
value if you want to be able to restore it.

IMOP the TrueDBGrid was well worth the money if you want to do much of
anything beyond the simplest of grids - for the documentation alone!

Hope this helps. -Rich


Quote:

>I've been hassling with this DataGrid (V6 sp5) problem for days now!  There
>must be a better way.

>I have a grid which allows users to insert new rows into a SQL Server table.
>The table actually has the visible fields in the grid, as well as a field
>which must be given a value programmatically.  I've tried various
>combinations if sticking the field in a hidden column in the grid, and
>deleting the column from the grid altogether (but still in the recordset).
>I have tried using the grid's OnAddNew event to stuff the value into the
>hidden field (tried both stuffing it into the hidden column, or directly
>into the recordset).  Either way I do this, the recordset decides that it
>has been changed., and wants to update if the user moves off of it.  (which
>is not appropriate when the user didn't type anything).

>I have not been able to figure out an event hook to prevent this. There are
>scads of events fired from the DataGrid, but none of them seem to be in the
>right place at the right time to do something like .CancelUpdate.

>Can someone please suggest a way to do this?  Am I asking too much from the
>DataGrid control?

>Thanks very much for any guidance here.

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts



Sun, 14 Sep 2003 07:46:19 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Need some help with DataGrids (DataGrid-->DataGrid, DataGrid-->Dataset, DataGrid-->XML)

2. Nightmares with the apostrophe!!!!!!!!!!!!

3. My Worst Nightmare: Error Accessing File

4. VBE password nightmare

5. Control Nightmare

6. RegEx - my personal illogical nightmare

7. Nightmare with ASP.NET

8. Deleting row nightmare

9. Printing nightmare...I'm losing my mind!!!

10. Socket nightmare

11. Resource File Usage is an absolute nightmare

12. OleDataAdapter.Update INSERT nightmare...

 

 
Powered by phpBB® Forum Software