| By Bruce Armstrong | Article Rating: |
|
| August 5, 2005 10:45 AM EDT | Reads: |
28,663 |
The one minor issue with this approach is that the DataWindowControl, by default, won't let the user tab out of columns that are marked as 'required' without entering data. It's often better to let the user move out of required columns and simply do the validation just before a database update. To do this, we add a dw_product_ItemError method, as shown below, that lets the user move out of the required columns without entering data. Note that this function is also quite generic and could be used on any DataWindow object.
DW.NET dw_product_ItemError
'by default the DataWindow will generate an error message
'when ever the user moves off a required column without populating it
'we want to delay that until the user is ready to submit the record
'to the database, but we also want to do the required field check
'dynamically using FindNextRequiredColumn, rather than checking
'individual(columns)
'is the new value an empty string
If e.Data() <> "" Then
e.Action = ItemErrorAction.Reject
Exit Sub
End If
'is the current value null
If dw_product.IsItemNull(e.RowNumber, e.ColumnName) Then
e.Action = ItemErrorAction.RejectAndAllowFocusChange
Exit Sub
End If
'otherwise set it to null
dw_product.SetItemNull(e.RowNumber, e.ColumnName)
e.Action = ItemErrorAction.RejectWithNoMessage
When users want to add a new product, they hit the Add command button and the btnAdd_Click method is called. In the VB.NET version, a ClearForm method is called that resets each of the individual controls to a default value. That instance variable that tracks the insert/update status is also set and the Add and Delete buttons are disabled. In the DW.NET version, we don't need a ClearForm method. Instead we simply do an InsertRow on the DataWindow control, and the columns in the newly created row automatically take the initial values provided in the DataWindow Object. Since the DataWindowControl is tracking the insert/update status for us, we also don't need that instance variable. And since the DataWindow control can handle updates on multiple rows simultaneously, we don't constrain the user by disabling the Add or Delete buttons either. The last thing we do in the DW.NET version of the btnAdd_Click method (as shown below) is scroll the dw_productlist DataWindow to make sure the newly inserted row is visible there as well as in the data-entry area.
Finally, we'll look at what happens when the user wants to delete a product. As you might have come to expect by now, the VB.NET DeleteProduct method contains 40 lines of code in which the SQL delete statement is constructed and executed. The DW.NET version of that method, as shown below, contains seven lines of code. We simply issue a DeleteRow on the DataWindowControl and then use the UpdateProduct method to handle the database update the same as we did for the inserts and updates.
DW.NET DeleteProduct
Try
Dim row As Integer = dw_productlist.CurrentRow()
dw_productlist.DeleteRow(row)
UpdateProduct()
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
End Try
Conclusion
As we've seen, DataWindow.NET technology can be used to simplify the generation of WinForms application development when database interaction is involved. Once the DataWindow Object is generated from the SQL select statement, it automatically handles the generation of SQL insert, update, and delete statements. And the update statements generated by the DataWindow technology automatically deal with issues such as optimistic concurrency and update collisions. The DropDownDataWindow edit style relieves the developer of having to develop code to populated dropdownlistboxes. The ShareData functionality lets the same result set be used to populate different DataWindowControls that provide different views of the same data; even different rows in that result set. Finally, DataWindow Object edit style properties and DataWindowControl methods let us easily implement required data validation generically.
Published August 5, 2005 Reads 28,663
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Bruce Armstrong
Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.
![]() |
alvin 07/23/08 08:36:24 PM EDT | |||
how can i change the highlight color of selected row? the default is dark blue which is too heavy. thanks |
||||
![]() |
Allan A. Cartagenas 08/18/05 04:38:53 AM EDT | |||
Where can I download the file frmDWMain.vb? The link to download the file is not included on the article. Thanks |
||||
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- How PowerBuilder Got Its Groove Back
- The Cloud Has Cross-Border Ambitions
- Ulitzer Names The World's 30 Most Influential Virtualization Bloggers
- Ulitzer Named "New Media" Partner of Greatly Anticipated iStrategy Event in Berlin
- Risks and Enterprise Mobility?
- Steps for Success in Enterprise Mobility?
- Are Mobile Luddites Resisting Mobility?
- The Difference Between Web Hosting and Cloud Computing
- Sybase CTO to Speak at 4th International Cloud Computing Expo
- Why SOA Needs Cloud Computing - Part 1
- Cloud Expo and The End of Tech Recession
- The Transition to Cloud Computing: What Does It Mean For You?
- Five Reasons to Choose a Private Cloud
- Seeding The Cloud: The Future of Data Management
- The Threat Behind the Firewall
- Economy Drives Adoption of Virtual Lab Technology
- Tips for Efficient PaaS Application Design
- A Rules Engine Built in PowerBuilder
- Sybase Named “Silver Sponsor” of iPhone Developer Summit
- Where Are RIA Technologies Headed in 2008?
- PowerBuilder History - How Did It Evolve?
- The Top 250 Players in the Cloud Computing Ecosystem
- Custom Common Dialogs Using SetWindowsHookEx
- DDDW Tips and Tricks
- OLE - Extending the Capabilities of PowerBuilder
- DataWindow.NET How To: Data Entry Form
- Book Excerpt: Sybase Adaptive Server Anywhere
- Sybase ASE 12.5 Performance and Tuning
- Working with SOA & Web Services in PowerBuilder
- Office 2003 Toolbar: A New Look For Your Old PowerBuilder App
- Dynamically Creating DataWindow Objects

































