Page 1
Page 2
Page 3
Listing 1, shows the functions provided
by the supporting modFileListSupport.bas file. This files contains
the important function needed to create our document list view
correctly.

Listing 1
Each row of our list contains a document name,
the date created and the size of the document. As discussed above,
we have special formatting needs to minimize the number of characters
used on the display. The function FormatDate handles the
conversion of the files date stamp to the appropriate style. This
function checks to see if file's date is the same as today. If
so, we display the file's creation time instead of date. Our FormatSize
function attempts to find the magnitude of the file (is it Kilobytes,
Megabytes, etc. in size?). We do this to minimize the real-estate
needed to display the size of the file.
The standard list allows the user to sort
by name, size, date, and file type. Our file list does not include
sorting by type since we are limiting ourselves to one file extension.
However, we are allowing the users to sort by the other methods.
The list view control allows us to sort a column by setting the
SortKey property to the index of the sub-item we want to
use. However, sorting is done as a String (i.e. alphabetically).
As you know, we can't sort our formatted dates or sizes as Strings
because the order will be completely wrong (01/01/01 will come
before 02/01/00). The function SortableDate generates a
string that, when sorted, will appear in chronological order.
Our ListView component will include a hidden column to store the
date in this format. I also subtract the size from a large number
to create a set of leading "9"'s to insure numeric and
alphabetical order are the same and store it in a hidden field.
The last two noteworthy functions are ListSubdirectories
and LoadFileListBox. The ListSubdirectories function will
find all the children directories of a specified path. We need
this to find all the sub-directories under "My Documents"
and it provides a nice example of listing directories.
The grunt work to load our list of documents
is performed by the LoadFileListBox. This function takes
the list view from our form and reads all the files of the appropriate
type from a list of directories specified. Each directory in the
list passed in (a "|" separated list in a String) and
the subroutine fills the list box with the data read in for each
file from the directories. For simplicity, I've assumed the proper
columns have been created and are expected in the order we will
fill them.
Listing 2, shows some of the more interesting
code from the document list view form.

Listing 2
When the form is loaded, we create an ImageList
to hold our file's graphic and assign the variable ext to the
extension we are looking for (txt for example). After setting
the ListView control's size based on the status of the
SIP, we call the function needed to populate our controls. The
subroutine CreateListView sets up our ListView control
that contains the list of files the user can select. Notice, we
add two columns with a width of zero to contain the unformatted
size of the files and the special sortable date. As an aside,
Microsoft also requires applications to handle SIP size changes
correctly to earn certification. We need to keep our input boxes
from disappearing under the SIP when it's visible. Our application
handles this by changing the size of the list view control based
on whether the SIP is enabled or not.
PopulateListView sets up everything
prior to calling the helper routine LoadFileListBox. One
of the chores this routine does is to create the delineated list
of directories that we need for our selection List controls and
for loading the ListView control.
The lstSort_Click and lstDirectories_Click
show how we handle when a user selects a new directory or method
of sorting.
That's it. It's not that hard to build out
a real application using this as a framework. The biggest task
is to implement a form to handle the real work. In many cases,
you can re-use your existing forms, just use the show method for
the form and change the projects properties to use the list view
form as the startup form. Remove your "File" menu and
call your existing load functions with the file name picked from
the list. Finally, add some code to implement what happens when
the new and options menu items are selected and your ready to
go.
Conclusion
Creating our own list view for documents
provides some valuable lessons in a few areas. I'm not claiming
my small utility will get you "Ready for Windows CE"
certified, but we got a chance to learn how to create a document
list/card view. We used it to list documents, but the same techniques
could be used to list contacts, action items, notes, or anything
else your application might keep track of! Also, we looked at
reading lists of files and directories, as well as building an
application using the list view control that used special formatting
and sorting capabilities.
We had a chance to learn about becoming "Ready
for WindowsCE" logo compliant from the folks at Veritest.
We'll discuss some more about certification in future articles,
but until them I highly recommend you check Veritest and the guidelines
out!
Tune in next time for more on earning Logo
certification and, of course, more code.
(PS, if any of you know how we can save all
this trouble and use the built in "DocList", let me
know!)
Previous Page