DEVBUZZ Homepage Techniques for filling lists using the .NET Compact Framework
 
Web www.devbuzz.com
  HOME PAGE
  All Articles
  Advertise
  Consulting

 Development
  Discuss - Forums
  Still in the box?
  .Compact Framework
  Code Snippets
  SQL Server CE
  Database
  MS Resources
 Stores
  Developer Controls
  Pocket PC Hardware
  Pocket PC Software
  Pocket PC Books
  .NET CF Books
  Book Reviews
  SPB SW Discounts
  RESCO SW Discounts
 DEVBUZZ Info
  About Us
  Help
  Join our email list
  Links & Ratings
  Press & Comments
  Pocket PC version
  Software Reviews
  Hardware Reviews
 Authors
  Authors
  Article Guide
  Competitions
 Resources
  Developers
  Register
  Login

  SPB Discounts!
 Columnists
  Rick Winscot
 Past Blast
  Personal Media Ctr
  Gizmobility
  eVB Legacy
  Old news
  Hosted Software
  Wireless
  Newsletters
  Carl Davis
  Upton Au

 Pocket PC Registry
  Join the registry
  View current list
 Current Poll
Are you converting to .NET Compact Framework?
Yes, it has changed my life!
No, I'm sticking with eVB
.NET CF what's that`?

Current results
3431 votes so far
 Recent Forum Threads [goto forums]

Get Computername
read... (67 hits)


Great aid to development productivity
read... (82 hits)


ThreadingTimer sample code
read... (143 hits)


Multithreading with .NET CF
read... (194 hits)


Moving from eMbedded Visual Basic to Visual Basic .NET
read... (166 hits)


.NET Compact Framework 2.0 Service Pack 2
read... (226 hits)


Transfer Data from SQL Server 2000 to SQL Server Compact Edition
read... (298 hits)


This protocol version is not supported
read... (236 hits)


Converting Lowercase to uppercase wont work
read... (203 hits)


Direct access to MS SQL Server 2000
read... (374 hits)


Creating SDF file in Desktop
read... (513 hits)


Winsock in CF.NET
read... (316 hits)


Using Pocket Outlook to submit HTML page form with MAILTO action
read... (420 hits)


Missing file "System.Data.PocketPC.asmmeta.dll"
read... (268 hits)


HP iPAQ hw6915 Serial Port Issue
read... (309 hits)


Info on the recent forum changes
read... (341 hits)


SqlServer tools from Redgate
read... (383 hits)


Arrow keys and Hardware navigation button
read... (393 hits)


O2 XDA lls pin sync cable to comport
read... (322 hits)


Creating dynamic folders on Pocket PC OS
read... (299 hits)

Custom Windows Mobile software development.
LBS Challenge 2007
LBS Challenge Eight previous NAVTEQ Global LBS Challenge® participants have received venture capital funding and nine past LBS Challenge winners have launched commercial applications on major wireless carriers. Register your non-commercial LBS application in the 2007 NAVTEQ Global LBS Challenge in one of three regions: Americas, Europe-Middle East-Africa (EMEA) or Asia-Pacific(APAC). You could win a share of $2 million in prizes. This could be your year.
Dream. Develop. Win.

Development | .NET Compact Framework

Techniques for filling lists using the .NET Compact Framework
Written by Derek Mitchell  [author's bio]  [read 45818 times]
Edited by Derek

Download the code   Discuss this article   .NET Compact Framework   

Page 1  Page 2 

Different techniques for filling lists using the .NET Compact Framework

I started writing this tutorial last week before I got sidetracked by the SQLCEDataAdapter. In essence as I was putting together the test data for this tutorial I realized that the technique being used to create the SQL Server CE database was a tutorial in and of itself. So if you have any questions about the attached code relating to creating the test data read the .NET Compact Frameworks & the ADO.NET Data Adapter article where I explain how I bridged the data from an XML data source into a SQL CE database.

So you've embraced the .NET Compact Framework and you're nashing your teeth trying to find out how to add items to a list or combo-box. Or you've heard that the performance of binding the dataset to the list is terrible! Well hopefully we can kill two birds with one stone. In this tutorial we will investigate two techniques to fill a combo-box and measure the performance of each. The first technique binds a data view to the combo-box and the second is much classier. (er a little weak in the humor department but it is 1:30 am...)

Using a dataview

The easiest way to get table information into a combo-box is to expose a table from a data set using thedata view. Take a look at this code used to fill the combo-box cbo1:

Dim oTimeIt As New TimeIt()
Dim dvTest As DataView
If sql.ceConnect Then
mFilling = True
cbo1.Items.Clear()
data.Clear()
cbo1.Visible = False
sbar.Text = "Filling combobox using dataset." : sbar.Refresh()
oTimeIt.Start()
Dim SqlDATest As New SqlCeDataAdapter("SELECT DevbuzzID, TestName FROM DevbuzzTable order by TestName", sql.connCE)
SqlDATest.Fill(data, "DevbuzzTable")
dvTest = New DataView(data.Tables("DevbuzzTable"))
cbo1.DataSource = dvTest
cbo1.DisplayMember = "TestName"
cbo1.ValueMember = "DevbuzzID"
oTimeIt.Finish()
Label1.Text = oTimeIt.Elapsed() & " seconds"
cbo1.Visible = True
sbar.Text = "Finished." : sbar.Refresh()
SqlDATest = Nothing
sql.Disconnect()
mFilling = False
End If

Firstly we grab the test data from the SQL Server CE database using:

Dim SqlDATest As New SqlCeDataAdapter("SELECT DevbuzzID, TestName FROM DevbuzzTable order by TestName", sql.connCE)
SqlDATest.Fill(data, "DevbuzzTable")

You will notice the terrible syntax (at least in my mind) of the data adapter fill method. For a long time I couldn't work out why I find the data adapter syntax confusing - then it hit me - instead of SqlDATest.Fill(data, "DevbuzzTable") it should really be data.Fill(SqlDATest, "DevbuzzTable") - think about it, the data data set it being filled not the SQLDATest data adapter. Well now that I have that little rant off my chest we can move onto the exposing the DevbuzzTable test data using the data view. This is the command:

dvTest = New DataView(data.Tables("DevbuzzTable"))

Now all we need to do is bind the combo-box to the dvTest dataview. We bind the column we want to display to the DisplayMember property and the key we wish to return to the ValueMember property and we're done! When you a click on the combo-box you can access the value of the corresponding ValueMember using the following code:

Dim row As DataRowView = CType(cbo1.Items(cbo1.SelectedIndex), DataRowView)
MessageBox.Show(row("DevbuzzID"))

When you access the ValueMember property you are really accessing the underlying datarow value of the data view.

Performance!!

The performance of this technique is pretty dismal when compared to the next technique I will show you and I would only recommend using it for prototype solutions such as a proof-of-concept type application. By the by, the double firing you see on the combo-box is the result of a beta 1 bug. I didn't use any work-around code since I want the attached sample code to be valid for the final release. Just add a variable to trap the first event.

Typically on my test device (Toshiba e570) I see an elapsed time of about 11-13 seconds to fill a combo-box with 500 rows using the bound data view technique.

Next Page 

Back to .NET Compact Framework | [Article Index]

 

Back to the top of the page.
Chris De Herrera's Windows CE Website Windows CE News & Information Source
Copyright ©2000-2007 by DEVBUZZ.COM, Inc., NJ. USA.MSDEVELOP