Navigating and updating with datagrid and adodc
- From: "sait" <sait@xxxxxxxxxxxxx>
- Date: Wed, 11 Jan 2006 03:41:02 -0800
Take a look at this page:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dbgrid98/html/vbevtOnAddNewEvent.asp
My understanding of the description of the OnAddNewEvent by Microsoft, is
this:
1. The user navigates to the AddNew row in the DataGrid.
2. The user types a character or makes a selection in a combo or radio.
3. The OnAddNewEvent fires.
4. AddNewMode is set to AddNewPending.
Now start up a simple project. Add a Form. Put a DataControl like adodc on
the form. Put a datagrid on the form.
Make the propriate connections to a database by setting the ConnectionString
- property for the adodc. Set the RecordSource property for the adodc to some
table with some fields. Just SELECT some fields in the table.
Set the EOFAction for the adodc to adDoAddNew. Now set properties for the
DataGrid. TabAction = dbgGridNavigation. WrapCellPointer = True. AllowAddNew
= True. AllowUpdate = True. DataSource = your adodc on the form.
Add some data to the table. Now, if you stay on the last updated record in
the grid, there will be a new line with an asterix below. This is the addNew
- line. Right? Now put the following code in the project:
Private Sub dgMyGrid_OnAddNew()
If dgMyGrid.AddNewMode = dbgAddNewCurrent Then
Debug.Print "dbgAddNewCurrent"
ElseIf dgMyGrid.AddNewMode = dbgAddNewPending Then
Debug.Print "dbgAddNewPending"
End If
Now compile and run this project.
Navigate to the last updated record in the grid, and use the TAB-key to
navigate to the first cell in the AddNew-row. In the immidiate window you
will see dbgAddNewCurrent. So the OnAddNew-event is fired on the navigation
with the tab-key, not when he/she types some character value.
The same happens if you navigate to the AddNew - row with a click of the
mouse.
Now if you try to enter some character in a cell in the AddNew-row, there
will be no OnAddNew-event fired. So the information on Microsofts webpage
concerning OnAddNew Event seems to be wrong.
What I want to achieve is this:
1. User tabs from the last updated row to the AddNew-row: Nothing happens.
2. Alternatively, the user clicks some cell in the AddNew - row: Nothing
happens.
2. User enters a character in the AddNew row: The record is imidiately
updated, and a new record is added. Cursor stays.
I've tried to achieve this functionality with several techniques, without
any luck.
The problem is that AddNewMode have to be dbgAddNewPending to call Update,
and you have to call Update or AddNew to update the record and then get a new
row. If you try to call AddNew or Update when AddNewMode = dbgAddNewCurrent,
then you get an error.
When you fire the OnAddNew Event, Microsoft says that the AddNewMode =
AddNewPending. This isn't true for my project. The OnAddNew event seems to be
fired imidiately after the user navigates to the AddNew-row, and the user
don't have to type any character at all. The testcode I have put in the
OnAddNew-event also shows that the AddNewMode = dbgAddNewCurrent and not
pending, as the documentation from Microsoft says.
If your table has 2 or more columns, then navigating from the first cell
you're typing in to the next cell in the AddNew row will set AddNewMode =
dbgAddNewPending. As soon as the Pending mode is the current mode, it is
possible to update the record. But it's no proper solution to move around the
grid to achieve the right AddNewMode.
The clue here is to achieve pending - mode as soon as the first character is
typed in a cell in the AddNew row. I can't find any way to code this right.
As long as the user doesn't move to the next cell, the AddNewMode is
AddNewCurrent, no matter how many characters he/she types.
The AddNewMode - property is read only at runtime, so there is no
possibilities of forcing the desired mode.
I hope someone can help me with this.
Sait
.
- Follow-Ups:
- Re: Navigating and updating with datagrid and adodc
- From: Mark J. McGinty
- Re: Navigating and updating with datagrid and adodc
- Prev by Date: Re: MS ADO Memory Leak FIX (at last??) for VB6
- Next by Date: Re: Navigating and updating with datagrid and adodc
- Previous by thread: Group headers in a VB datareport
- Next by thread: Re: Navigating and updating with datagrid and adodc
- Index(es):
Relevant Pages
|