Click here to Skip to main content
13,296,823 members (40,906 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 13 Jun 2008


, 13 Jun 2008
Rate this:
Please Sign up or sign in to vote.
A virtual WTL ListView control on an SQLite3 table or view.


AlphaView uses a listview in virtual mode to see data stored in an SQLite 3 DB. When a ListViewCtrl is in virtual mode (via LVS_OWNERDATA), no data is stored in the listview itself. The listview asks for data via two notification messages:


The first notification asks for the data by item, and the second one helps an optional cache manager to pre-fetch data. The real work is done by the database back end, in this case, the amazing SQLite engine.


Virtual lists are nothing new, of course. You can see it as a Model - View system, the list view is the view and the DB the model. Data is fetched on demand, when the user scrolls the list (or when the list is resized).

In AlphaView, the code is separated in to two classes:

  • cached_alpha_view
  • alpha_view

alpha_view is a classic WTL listview that handles Windows messages and notification. Clicking on a column sorts the data on that column (but all the work is done by SQLite). cached_alpha_view uses the LVN_ODCACHEHINT notification to pre-fetch a block of data, using the sqlite3_get_table interface. It also computes the size of the data, and the schema to setup the listview columns.

Using the code

To use alpha_view in your project, just include alpha_view.h and stringutil.h. alpha_view can be used as a normal WTL ListViewCtrl, it just needs a SQLite3 connection and the table to display. The DB connection is obtained from sqlite3_open.

struct sqlite3 *db;
sqlite3_open(file_name, &db);
//create a new control with a db connexion and a table name
alpha_view * v = new alpha_view(db,table_name);
//then creates the window.

Don't forget the LVS_OWNERDATA, of course. The owner window should also reflect the notification messages. Also provide a bitmap for sorting arrows, there is one in the src directory.

Points of interest

In the the sample application, I use a splitter with a treeview in the left pane and a tab control in the right one. When the user opens a SQLite file, the treeview is populated with all the tables. When the user selects a table with a double click, a new alpha_view is created and inserted in a new tab index. From there, everything is handled by the alpha_view.

This class should also work on Windows CE/PocketPC.

What is provided

An executable to test the code (400L with SQLite inside!): alphaview.exe. It should run as is. A sample SQLite3 database: nwind.db, and a sample VC6 project (you will have to adjust the path to wtl80) is also included. SQLite3 is provided in a C file. But you can use the official distribution, of course.


  • First release.


This article, along with any associated source code and files, is licensed under The MIT License


About the Author

Noel Frankinet
Architect strategis
Belgium Belgium
No Biography provided

You may also be interested in...

Comments and Discussions

General[Message Removed] Pin
immetoz1-Oct-08 10:42
memberimmetoz1-Oct-08 10:42 
Spam message removed
GeneralRe: Good Pin
Noel Frankinet1-Oct-08 10:59
memberNoel Frankinet1-Oct-08 10:59 
GeneralMissing the meat Pin
Neville Franks16-Jun-08 12:30
memberNeville Franks16-Jun-08 12:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 13 Jun 2008
Article Copyright 2008 by Noel Frankinet
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid