Data Access Worldwide Knowledge Base
Article ID 2267 Article Title HOWTO: Copy a row in a dbGrid Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2267 KBase Category VDF11 Date Created 11/28/2006 Last Edit Date 11/28/2006
Article Text
QUESTION:
I would like to implement something that when the user double-click or right-click an existing row, the selected row gets copied to the end of the grid -- i.e. the user will get a new row (with the same values as the selected row), where he then may change some values and save the row.
Does anyone know if there are predefined functions to support this or what would be the best way to implement this?
ANSWER:
The following code - tested on the orderdtl dbgrid in order.vw - copies on a key stroke (Ctrl+R) the current row to a new row in the dbgrid. The data is copied into an array of values and then a new row is added to the end. The stored values are copied to the new row.
On_Key Key_Ctrl+Key_R Send CopyRow
Procedure CopyRow
Handle hoServer
Boolean bHasRecord bShouldSave
Integer iBaseItem iItemsPerRow iLastItem iItem iElement
String[] sValue
Get Server To hoServer
If (hoServer > 0) Begin
Get HasRecord Of hoServer To bHasRecord
If (bHasRecord) Begin
Get Should_Save Of hoServer To bShouldSave
If (Not (bShouldSave)) Begin
Get Base_Item To iBaseItem
Get Item_Limit To iItemsPerRow
Move (iBaseItem + iItemsPerRow - 1) To iLastItem
Move 0 To iElement
For iItem From iBaseItem To iLastItem
Get Value iItem To sValue[iElement]
Increment iElement
Loop
Send End_Of_Data
Send Down
Move 0 To iElement
Get Current_Item To iBaseItem
Move (iBaseItem + iItemsPerRow - 1) To iLastItem
For iItem From iBaseItem To iLastItem
Set Value iItem To sValue[iElement]
Set Item_Changed_State iItem To True
Increment iElement
Loop
End
Else Begin
Error DFERR_OPERATOR "You cannot perform this action while changes are pending"
End
End
Else Begin
Error DFERR_OPERATOR "You need to have a valid record in the buffer before this action will work"
End
End
End_Procedure
Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.