Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A basic DataListView implementation

0.00/5 (No votes)
21 Nov 2005 2  
It implements an object that is intended for data viewing; the idea was to derive from a ListView.

Sample Image - DataListView.jpg

Introduction

This is my first article, so please do not be hard on me :). The purpose was to make the base of a data viewing control like the one found in Microsoft's applications, or the one proposed by the "magic controls". So the main goal was the looks defined by looks and a basic functionality.

The main idea

The main idea was to extend a ListView, and work with its properties. Customize it to show only lists, inhibit read only to false, and full row select to true. Also, make it possible for a data source, just add a new object into the control to hold the data and make some functions to process the given data source. Make a row in the control for any row in the data source... Implement some properties for the control to be functional, properties like: SelectedItem or SelectedItems[].

Nothing hard ... except the interception of an row drawing event. Here is the big problem, if you want a nicer drawing. So the code must intercept the draw item message and process it custom. In order to intercept this you must set the control style so that the desired message to be passed to you and not be default handled.

For the control to be useful, I had to implement some rudimentary table styles ... if it can be named so :). There are some functions made to make it all possible in an easy code snippet.

The control is easy to use, like the DataGrid:

DataSet dataSet = new DataSet();
DataListView dataListView = new DataListView();
// let windows designer place the control (dataListView) on the screen...

// initialize dataSet with some data...

dataListView.DataSource = dataSet; // show the data on the control

dataListView.DataMember = "TableNameInDataSet"; // set the data member

Instead of ending

The code is not meant to be "the best", it is easy to understand and can be heavily improved in all ways. I end this article with my usual statement : "I hope you understand...".

Anyway if you like my idea and you ever decide to use my control, you are free to modify it as you wish, but you can mention me somewhere there on the about window :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here