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.
Comments