| By Bruce Armstrong | Article Rating: |
|
| August 5, 2005 10:45 AM EDT | Reads: |
28,664 |
Similar to the methods used to populate the dropdownlistboxes, the VB.NET PopulateProductList method has approximately 50 lines of code used to populate the product listbox. As shown below, the DW.NET version has 18 lines of code in which we establish an ADO.NET connection, associate it with a Sybase.DataWindow.AdoTransaction object, assign that to the DataWindowControl, and then retrieve the DataWindow control. We don't have to worry about copying the data from an SQLReader to our display control as the VB.NET version does. That's all handled in the DataWindow Object.
DW.NET PopulateProductList
Try
Dim conn As New System.Data.OleDb.OleDbConnection
conn.ConnectionString() =
ConnectionString
conn.Open()
Dim SQLCA As New Sybase.
DataWindow.AdoTransaction
SQLCA.Connection = conn
SQLCA.BindConnection()
dw_productlist.SetTransaction(SQLCA)
IsRetrieving = True
dw_productlist.Retrieve()
IsRetrieving = False
SQLCA.Connection.Close()
If dw_productlist.RowCount() > 0
Then
dw_productlist.SelectRow(1, True)
End If
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.
Critical, "General Error")
End Try
The one unusual thing here is the IsRetrieving variable we set before and after retrieving the DataWindowControl. To understand why that's there, we have to look at how both forms select a product in the product list (including the initial selection of the first item by the PopuplateProductList method).
In the VB.NET form, the lstProducts_SelectedIndexChanged method is used to respond to the selection of a product in the product list. Because the other controls on the form are separate controls, the VB.NET method calls a PopulateForm method - another 65 lines of code that are needed to retrieve the additional product data from the database and populate those controls with it. The VB.NET form then sets the Mode variable (remember that it's manually tracking whether the user is adding a new record or editing an existing one) and enables the Add and Delete command buttons.
In the DW.NET form, two methods are used to respond to the selection of a product in the product list. The dw_productlist_RowFocusChanging method (as shown below) is called before the new product is made the current product in the product list. We're going to attempt to save any changes the user made to the original record before letting him to move to another item. So we do an AcceptText on the DataWindowControl and then, if the ModifiedCount is greater than 0, call the UpdateProduct method of the form to save the data. The AcceptText method ensures that the last data entry made by the user has been accepted into the control before attempting the update. If the update succeeds, the two calls to the SelectRow method of the DataWindowControl set the selection indicator to the newly selected product. The first call to the function de-selects that indicator for the entire control (all rows); otherwise the row selection indicator would appear on several rows.
dw_productlist_RowFocusChanging
If Not dw_product.AcceptText() Then
e.Cancel = True
Exit Sub
End If
If (dw_product.ModifiedCount() > 0) Then
UpdateProduct()
End If
dw_productlist.SelectRow(0, False)
dw_productlist.SelectRow(e.NewRowNumber, True)
The dw_productlist_RowFocusChanged method (as shown below) is called after the newly selected product becomes the current product. Here we simply scroll the active row in the free form DataWindowControl to make that product visible (the free form DataWindowControl only shows one row at a time). Remember that the dw_productlist DataWindowControl has all of the rows of product data in its memory and the dw_product DataWindowControl is sharing that same data (pointed to that same area of memory). The DataWindowControls not only display the data differently; they can also display different rows of data; so the purpose of the dw_productlist_RowFocusChanged method is to keep them in synch (showing the same product).
dw_productlist_RowFocusChanged
If e.RowNumber > 0 And Not
IsRetrieving Then
dw_product.ScrollToRow(e.RowNumber)
End If
Here's where that IsRetrieving variable comes in. The dw_productlist_ RowFocusChanging method isn't just called when the user selects a new product or the PopulateProductList selects the first item as the default. It's also called when the DataWindowControl is first retrieved. That's too soon for us though, and actually causes some problems. So we set the IsRetrieving variable to indicate when a retrieve is happening, and then tell the dw_productlist_RowFocusChanged method to ignore the request if that's the reason for the call.
Published August 5, 2005 Reads 28,664
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 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?
- Hot Event in Santa Clara Becomes Cool with the iPhone
- 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

































