Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / Windows Forms
Article

A basic DataListView implementation

Rate me:
Please Sign up or sign in to vote.
3.32/5 (13 votes)
21 Nov 2005CPOL2 min read 65.2K   245   18   8
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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Romania Romania
-

Comments and Discussions

 
GeneralNew feature and bug fix Pin
SGInut14-Nov-05 14:42
SGInut14-Nov-05 14:42 
GeneralRe: New feature and bug fix Pin
Stanciu Vlad21-Nov-05 7:16
Stanciu Vlad21-Nov-05 7:16 
GeneralNice job. nm Pin
eyoung703-Dec-04 10:33
eyoung703-Dec-04 10:33 
GeneralIf there are any problems Pin
Stanciu Vlad2-Dec-04 8:57
Stanciu Vlad2-Dec-04 8:57 
GeneralRe: If there are any problems Pin
sxzhang221-Mar-05 9:07
sxzhang221-Mar-05 9:07 
GeneralRe: If there are any problems Pin
Stanciu Vlad24-Mar-05 20:42
Stanciu Vlad24-Mar-05 20:42 
GeneralRe: If there are any problems Pin
sxzhang225-Mar-05 2:41
sxzhang225-Mar-05 2:41 
GeneralRe: If there are any problems Pin
Stanciu Vlad25-Mar-05 20:09
Stanciu Vlad25-Mar-05 20:09 

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.