Displaying Recordsets in a ListView

Overview

This example demonstrates a quick and easy way to pass a Recordset to the ListView Control and format control's content using Data-Aware Classes. Most of applications use data that is created and consumed at run time. Some-times, this may be all that you need, but what if you need to store data between sessions, or utilize data that already exists outside of your program?

To work with external sources of data, you can make your class data-aware.

Simply setting the DataSourceBehavior to 1 (vbDataSource), your class can act as a source of data for other objects.
A data source is a class that provides data from an external source to be consumed by other objects. A Data control is actuality an instance of a class that is a data source, but unlike the Data control, a data-aware class doesn't have to have a visual representation, and it isn't limited to a particular data interface such as DAO or RDO or ADO.

In fact, a data-aware class can act as a data source for any type of data, including traditional ODBC sources or any OLE DB provider, which makes much more powerful than a Data control.

Using such an approach it is very easy way to pass a Recordset to the ListView Control. Nice interface and behind the scenes actions for formatting any item in ListView: Bold / Italic / Regular Font Formatting for items; Color Formatting: every other row with any color; Icons in items on conditional formatting including Up/Down arrows for ascending / descending sort (put attention that sorting is correct, no matter that kind of data type it is).

Copy this code in, using the correct ADO refs and the correct ListView and it should work like a charm. To some this may already be apparent, to others perhaps not.

You might also like...

Comments

Alfred Yomtov

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson