Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Twitter Updates

    News

    New site design will be posted by Wednesday.
    6/2/2008 8:07:00 AM

    Windows Mobile Developer Controls
    Sapphire Soltuions
    Skip Navigation Links Breadcrumb Articles Breadcrumb Past Blast BreadcrumbStarting Out

    Performance Grid

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

    Download the code

    Page 1  Page 2  Page 3 

    What I was going to do was...

    Test 1 - Populate the grid using additem.

    Test 2 - Make the grid invisible, populate the grid using additem and then make the grid visible

    Test 3 - Make the grid invisible, append the data to a string, use .clip and then make visible

    Test 4 - Populate a text box using textbox.text = textbox.text & newdata

    Test 5 - Populate a text box by using a string, and assigning it to the text box at the end of the loop

    Test 6 - Populate the listview

    Test 7 - Make the listview invisible, populate it, make it visible.

    Emulator

    First I ran the code on the emulator. The system was a 1.2ghz laptop with 512mb of memory. The results were:-

    Test Task Time
    1 Populate the grid using additem. 17.87 seconds
    2 Make the grid invisible, populate the grid using additem and then make the grid visible 13.69 seconds
    3 Make the grid invisible, append the data to a string, use Clip and then make visible 5.99 seconds
    4 Populate a text box using textbox.text = textbox.text & newdata 73.30 seconds
    5 Populate a text box by using a string, and assigning it to the text box at the end of the loop 6.49 seconds
    6 Populate the listview 1.34 seconds
    7 Make the listview invisible, populate it, make it visible. 0.43 seconds

    The real surprise was how much quicker it was using the listview, rather than the grid. (The textbox was no real surprise, as I knew from VB6, appending to a string, and then setting the textbox to that string was far quicker than text1.text = text1.text & String.)

    iPaq

    Using the listview was almost 14 or 32 times quicker than the grid. But we all know that the emulator does not represent real life, so the program was 'compiled' and copied down to the Pocket PC (iPaq 3870 - Arm 206mhz with 64mb). This time the results were..

    Test Task Time
    1 Populate the grid using additem. 489.42 seconds
    2 Make the grid invisible, populate the grid using additem and then make the grid visible 477.37 seconds
    3 Make the grid invisible, append the data to a string, use Clip and then make visible 63.38 seconds
    4 Populate a text box using textbox.text = textbox.text & newdata 585.13 seconds
    5 Populate a text box by using a string, and assigning it to the text box at the end of the loop 17.57 seconds
    6 Populate the listview 18.60 seconds
    7 Make the listview invisible, populate it, make it visible. 7.11 seconds

    A real surprise. The emulator was really hiding what was happening!

    No real decision to make. Even though the Clip method proved to be the quickest way of filling a grid, it was time to trash the grid control and use the listview control instead. But this gave me a problem - I want to be able to click on an item in the control, and copy it to the clipboard. I could do this using the text box by making it locked = true and hideselection = false, but I still prefer to use the listview.

    Time for a bit more investigation

    There is a lot of good documentation around on the listview control. Chris Tacke has an excellent eVB listview tutorial on his site for example and Brad Martinez (http://www.mvps.org) has some excellent VB6 articles. The subitem highlighting was ported from Brads' VB6 Code.

    So how do we make the listview look like a grid. Well, we can add gridlines to the listview using the API, but for some reason the gridlines are offset, and don't look pleasing. The other thing we can do is turn on 'full row select', by...

    Const LVS_EX_FULLROWSELECT = &H20
    lv.SetFocus
    SendMessage GetFocus(), _
    LVM_SETEXTENDEDLISTVIEWSTYLE, _
    LVS_EX_FULLROWSELECT, _
    LVS_EX_FULLROWSELECT

    Now, the other thing I wanted to do was select an item. We can do this using the excellent article and dll Calling complex Windows API functions from eVB.

    First we need to be able to trigger a popup menu. The listview does not contain a mousedown event, so I used the Messagece control from www.intelprog.com (other controls are available). When we hit a mousedown message, we do the following to work out the x and y co-ordinates.

    Y = Int(lParam / 65536)
    X = lParam - Y * 65536

    Then, using the x and y, we call our routine for detecting which subitem was clicked on...

    Find_Subitem X, Y

    Previous Page  Next Page