Click here to Skip to main content
Click here to Skip to main content

AlphaView

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

Introduction

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:

  • LVN_GETDISPINFO
  • LVN_ODCACHEHINT

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.

Background

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.
    v->Create(*this,rcDefault,wtable_name,
        WS_CHILD| WS_TABSTOP | 
        WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
        LVS_REPORT | WS_HSCROLL| WS_VSCROLL |
        WS_BORDER  | LVS_SHOWSELALWAYS | LVS_OWNERDATA ,0,0);

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.

History

  • First release.

License

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

Comments and Discussions

 
GeneralMissing the meat PinmemberNeville Franks16-Jun-08 11:30 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 13 Jun 2008
Article Copyright 2008 by Noel Frankinet
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid