|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
This article is in the Product Showcase section for our sponsors at The Code Project. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.
This is a showcase review for our sponsors at The Code Project. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers. IntroductionCreating a list of customers is very common task. When creating applications in a Windows Mobile environment, a programmer has the difficult task of coping with a device that has a small memory, a small display and a slow processor. Therefore, designing an application for a mobile device can be a lot more tricky compared to desktop designing a desktop application. In this article I will demonstrate how easy it is to design and program Resco AdvancedList control on Microsoft .NET Compact Framework platform, in an application that displays a list of customers. The main features of this application will be:
Designing AdvancedListResco MobileForms Toolkit, which contains the AdvancedList control, can be downloaded here. After succesful installation, AdvancedList control should be present in the Visual Studio’s Toolbox. Drag it on the form together with one TextBox and design the main menu so that it looks like on the picture below:
Now we will use AdvancedList’s strong support for Visual Studio’s designer and thus have the most of the code generated. Go to the properties of AdvancedList control and edit its Templates property. In the Row Template collection editor add a Row Template to AdvancedList. Set its height to 16 and name it 'Simple'. From now on I will refer to this Row Template as to simple Row Template. Edit the Once the user selects a row, we want additional information to be displayed about the customer. Besides his name, we want to display the Address, City and Country. We need to create a new Row Template that will be used to display this data from a row. Go back to Row Template collection editor and add one more Row Template. Name it 'Selected'. Change ForeColor to 'HighlightText' and BackColor to 'HighLight'. Change its Height to 48. Add four TextCells to this Row Template. Name them:
The size of the used font is 8 points by default. Having one row 16 pixels high is adequate to display text using an 8 point sized font. We will therefore make 4 TextCells 16 pixels high. It is now up to you to set their Bounds property so that they do not overlay (although they may) and that every TextCell's Text is readable. I used these values for Bounds:
In this sample, we will display data from a SqlCe database file called Northwind.sdf which you can download here. Then add it to your solution as a content. You can now inspect the Northwind.sdf database in the Server Explorer tool of Visual Studio. You will find out that it contains a 'customers' table which contains the same column names as we gave to the TextCells in the Selected Row Template. The We now need to let AdvancedList know that we want to use the simple Row Template to display unselected rows and the selected Row Template to display the selected rows. Set AdvancedList's AdvancedList is now ready to load the data. Loading the DataTo load the data from SQL CE databse, create the SELECT
ContactName, Address, City, Country FROM customers
Here is the code to make AdvancedList load the data. You can put it into the constructor of your form just below the Me.AdvancedList1.DbConnector.Command = m_Command
Me.AdvancedList1.LoadData()
These two lines of code(except of those that you used to create the Me.AdvancedList1.DbConnector.Command = m_Command
Me.AdvancedList1.LoadData()
DelayLoadWhat we created so far is just a simple list that allows the user to scroll it and select the customers to view further information about them. Let's make the list more sophisticated by using AdvancedList's Adding FilterThe TextBox at the top of the form will serve as afilter input textbox. As soon as user types any string into the textbox, the filter will display only those records, which contain the typed string. The filter will use the SQL CE database to get the results. We will now handle the Me.AdvancedList1.DataRows.Clear()
m_Command.CommandText = "SELECT ContactName, Address, City,
Country FROM customers WHERE ContactName LIKE '%" +
Me.TextBox1.Text + "%'"
Me.AdvancedList1.DbConnector.Command = m_Command
Me.AdvancedList1.LoadData()
CType(Me.AdvancedList1.Templates(0)(0),TextCell).SelectedText = Me.TextBox1.Text
CType(Me.AdvancedList1.Templates(1)(0),TextCell).SelectedText = Me.TextBox1.Text
Refining the ApplicationTo increase the user’s comfort and make the application usable on Smartphone platform, we will add support for hardware keys. To make AdvancedList support the hardware keys, simply use Visual Studio’s designer to turn on the Select Case e.KeyCode
Case Keys.Down
If (Me.AdvancedList1.DataRows.Count - 1 >
Me.AdvancedList1.ActiveRowIndex) Then
Me.AdvancedList1.ActiveRowIndex += 1
End If
e.Handled = True
Case Keys.Up
If (Me.AdvancedList1.ActiveRowIndex > 0) Then
Me.AdvancedList1.ActiveRowIndex -= 1
End If
e.Handled = True
End Select
We will add one final feature to the application. We do not know the size of display of the device the application will run on. If it is going to be a large display, then user could use it to display some additional information about every record and he would not care that the rows are a bit higher. On the other hand, if it is going to be a small display, he would probably appreciate, if the records were as brief as possible, so that many would fit on the display. We are now going to handle the events that occur if the user clicks the Show simple rows and Show detailed rows menu items, so that the user can choose the level of details displayed in each record. The first handler’s code will be: Me.AdvancedList1.LoadXml(m_sPath + "\SimpleRows.xml")
The second handler’s code will be: Me.AdvancedList1.LoadXml(m_sPath + "\DetailedRows.xml")
The XML files define AdvancedList’s settings (values of all its properties). You can save AdvancedList’s setting into an XML file any time in Visual Studio’s designer by right clicking it and choosing Save.
To make the whole application look more attractive, you can use the ability of AdvancedList to gradient fill the background of the Row Template objects:
ConclusionThe application that we created now fulfills all the requirements that we specified in the beginning. It implements a customer list that:
About Resco .NETResco is adominant provider of developer components and tools for mobile devices running Microsoft Windows Mobile operating system. Started with development of end-user applications which are currently the best selling, Resco moved on to creating developer components, libraries and tools providing developer companies in designing aprofessional looking, yet easy and comfortable to use interface. To find out more about Resco developer tools, click here. To find out more about Resco, click here. You can download evaluation version of Resco MobileForms Toolkit here.
|
|||||||||||||||||||||||||||