Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Review of Odyssey Software's free DataViewer control for eVB

Written by Pete Vickers  [author's bio]  [read 47796 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3 

Briefly, we are passing in the row. If the absolute position of the recordset is not this row, we will move to that record. We then use the column-1 to get the field value. In our sample project, this routine is called 16 times, as we are displaying 8 rows and 2 columns. As we scroll down, the 'GetItemText' event is automatically fired.

I was a little concerned by this at first, as scrolling up and down would generate a lot of database activity, but in practice, it works well.

Our sample gives us another option though - we can use 'getrows'. Use the GetRows method to copy records from a Recordset object into a two-dimensional array. So, instead of rs.movenext, we use…

AvarTable = rs.GetRows

This gives us a 2 dimensional array containing all the records. Again, setting the dataview rowcount to the number of records fires the 'GetItemText' event. This time however, the code reads...

If IsArray(AvarTable) Then
Text = CStr(AvarTable(Column - 1, Row - 1) & "")
End If

Instead of going to the database for the records, we are reading them from our array. This will give us some advantages we will see later, and we will use in our other sample project.

So, we now know how to populate the listview. If you have had problems following my garbled explanation of how it works, do what I did - single step through the code. It all becomes much clearer then.

The DataViewer contains more properties and events than the listview. ‘Hands up’ all those who want to use 'tap and hold' in a listview. The DataViewer supports this through context menus. Simply set the contextmenu property to 'True', and hold down the stylus. The 'showcontextmenu' event fires.

Private Sub dvRecs_ShowContextMenu _
(ByVal X As Long, ByVal Y As Long)

Dim hWnd As Long
Dim intSelection As Long
On Error Resume Next

hWnd = GetFocus()
intSelection = ShowPopupMenu(hWnd, X, Y)
Select Case intSelection
Case 1
Edit_Record
Case 2
If bGetRows Then
MsgBox "Delete record: " _
& CStr(AvarTable(0, _
dvRecs.Selection - 1) & "")
Else
MsgBox "Delete record: " _
& GetRecordsetFieldValue _
(rs, SaveRow, SaveCol)
End If
Case 3
Total_Records
Case Else
End Select
frmMain.SetFocus
dvwRecords.SetFocus
End Sub

Public Function ShowPopupMenu(hWnd As Long, _
Left As Integer, Top As Integer) _
As Integer

Dim hMenu As Long
Dim lOption As Long
Dim iMenuItem As Integer

hMenu = CreatePopupMenu()

' Edit menu items
lOption = MF_ENABLED
AppendMenu hMenu, lOption Or MF_STRING, 1, _
"Edit"
AppendMenu hMenu, lOption Or MF_STRING, 2, _
"Delete"
AppendMenu hMenu, lOption Or MF_STRING, 3, _
"Total Records"

ShowPopupMenu = (TrackPopupMenuEx(hMenu, _
TPM_LEFTALIGN Or TPM_TOPALIGN _
Or TPM_RETURNCMD, Left / 15, _
Top / 15, hWnd, 0))

DestroyMenu hMenu
End Function

This will give us a context menu with 3 items, Edit, Delete and Total Records on it. To demonstrate the use of Edit, we simply move the data from our data viewer to our text fields, and make the frame visible. The 'OK' button simply makes the frame invisible, but could easily write back any changes to our record.

Delete records is a dummy item, but Total records allows us to get a total of the numeric fields in the DataViewer. This explains why we used the 'getrows' method earlier. To total up using the normal method of 'movenext', we need to use the procedure GetRecordsetFieldValue, which may (most probably will) involve reading records from the database. If we use 'getrows', we can simply total up using our array. Using the emulator, it takes approx 50 milliseconds. Using 'movenext' it takes approx 850 milliseconds to total up. This was using 1000 records.

Previous Page  Next Page