Skip to main content

Articles

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 BreadcrumbCompact Framework

    .NET Compact Framework - Making the Switch!

    Written by Derek Mitchell  [author's bio]  [read 48729 times]
    Edited by Derek

    Page 1  Page 2  Page 3 

    Managing Forms

    As a VB programmer you were probably familiar with the Forms collection. In the beta release of .NET cf there were significant issues with the Form.Dialog functionality and .NET cf does not expose a Forms Collections so the fallback position is to show forms non-modally and manage the collection using your own collection class. To do this we implement our own forms collection class as follows:

    Class FormsCollectionClass : Implements IEnumerable

    Private formsColl As New Collection()

    Public ReadOnly Property Item(ByVal index) As Form
    Get
    Return formsColl.Item(index)
    End Get
    End Property

    Public Sub Add(ByVal newForm As Form)
    formsColl.Add(newForm)
    End Sub

    Public Sub Remove(ByVal thisForm As Form)
    Dim itemCount As Integer
    For itemCount = 1 To formsColl.Count
    If thisForm Is formsColl.Item(itemCount) Then
    formsColl.Remove(itemCount)
    Exit For
    End If
    Next
    End Sub

    Overridable Function GetEnumerator() As IEnumerator _
    Implements IEnumerable.GetEnumerator
    Return formsColl.GetEnumerator
    End Function

    End Class

    We can then declare an instance of this class in our main Module:

    Public Forms As New FormsCollectionClass()

    and add and remove our form to that collection using:

    Forms.Add(Me) or Forms.Remove(Me)

    in the form load and dispose events. Having this form collection allows us to enumerate through the list of form objects and manage our forms just as if we had the old VB6 forms collection.

    Techniques for filling lists using the .NET Compact Framework

    Another attractive technique that you will use when embracing .NET cf is filling lists (such as the combo-box, list-box, grid etc.) with objects. In VB6 the process would entail reading the data from the database and then adding a string to the list and an ID to the ItemData array. In .NET you add the actual object to the list. When a list item is selected you can address the SelectedItem directly and access any number of properties, not just the display name and ID. For example if you were to add a Client object to the list and select it you could then read the ClientID, Name, ContactInfo etc. - whatever properties the Client object exposed. For more information on this technique read the following DEVBUZZ article: Techniques for filling lists using the .NET Compact Framework (http://www.devbuzz.com/content/zinc_dotnet_compact_framework_combobox_pg1.asp).

    Switch...

    .NET cf is a vastly superior development environment to eVB and I hope this article has provided you with some assistance in one or two of the challenges that you will come across when you make the switch. Join the rest of us in the DEVBUZZ forums as we learn more about this exciting technology. (http://forums.devbuzz.com/Default.asp)

     

    Essential .NET cf Links

    Get the Smart Device Extensions

    • Go to BetaPlace.com.
    • Enter "SDEBeta" as the username and ".NetCF" as the password. Please note these are case-sensitive.
    • Complete the nomination survey.
    • Within a few days you will receive a confirmation e-mail with a BetaPlace username and password to access the Smart Device Extensions and .NET Compact Framework Beta program.
    • With the new credentials, you will be able to download the installation package and participate in the beta program.

    Supplemental .NET cf API Documentation

    .NET Compact Framework Runtimes

    Pocket PC 2002 SDK

    ActiveSync

    Exploring the Singleton Design Pattern:
    Mark Townsend Microsoft Corporation February 2002

    Techniques for filling lists using the .NET Compact Framework

    DEVBUZZ Forums

    Previous Page