PowerBuilder ‘Gotcha’ – Removing Blank Rows from Datawindow
I’m working with a ‘pre-Cambrian’ framework of sorts which has a datawindow ancestor with quite a lot of functionality in it. One standard piece in list type datawindows is to insert a blank row when the user opens a window. This way the user doesn’t have to click a ‘new’ button or do something else when they want to enter data. This is fairly standard user centric functionality.
Now if the user doesn’t do anything with the new row you need to make sure it isn’t going to generate an insert statement back to the database when the window is saved. The framework has functionality for this as well and it checks the row status via a GetItemStatus call checking for a DWItemStaus of New!. If it finds a row with this status it removes it from the primary buffer via a RowsDiscard call. This is not needed since a row with a status of New! doesn’t generate any SQL to the database anyway.
However, if the datawindow object has default values, after the insertrow the defaults are set and the DWItemStatus is now NewModified!. You cannot directly set this back to New!; you must issue a SetItemStatus for the row and set the DWItemStatus to NotModified! which results in the row having a status of New!. For more information see the PB help on SetItemStatus method (DataWindows).
You might also be interested in