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

Yet another databound ListView (This time for .net2)

, 5 Mar 2006
Rate this:
Please Sign up or sign in to vote.
Inherits from the ListView control and adds the functionality of allowing you to easily add a DataSource using .net2s BindingSource

Sample Image - DBListView.jpg

Contents

Introduction 

This control like so many before it, inherits from the ListView control and adds the functionality of allowing you to easily add a DataSource from which the list will be built.

If so many before me have built the same control, why you may ask am I reinventing the wheel?

Good question! And I have an equally good answer.

Because I am the first one to do it in .net2!

And why do I need to make one just for .net2? Won’t the earlier ones still work?

Yes they will and quite well. Just not as good as a true .net2 control will.
You see, Microsoft totally redid the DataBinding in .net 2(which shipped with vs2005). Everything is based around a new (non visual) component call the BindingSource for windows forms based programs and DataBindingScource for web based programs.

While the young and sexy asp.net v2 has been getting all the attention. Her older plainer sister Windows Forms has also learned a few new tricks.
This new BindingSource accomplishes a lot of cool things. But the best in my opinion is how much it hides what the data source is. To the control there is no difference whether the data is coming from a database through a DataSet, from a WebService through a custom class or from an operating system function in the form of an array of COM classes.

So creating a ListView that works off of the BindingSource is a major accomplishment. It was also extremely easy; the entire project is less than 4k! And a great opportunity for everyone to see what it takes to create a control for the new BindingSource.

The control is bare bones and I will be updating it shortly.

When I am done I will post another article explaining the interesting points of development.

In the mean time I am only posting a short article on how to use it.

Background 

Anyone who does database front ends in windows with .net will find this indispensable.

Using it couldn’t be easier! Take a look at the demo!

Anyone who knows the basics of C# or VB.net will find it a sinch.

Using the code 

Its quite easy. To use the control you need to add it to your form as you would any other control.

That is you either add it in code. Or if you add the project containing it to your solution it will showup right in your toolbox and then you can just drag it onto the form.

Once the control exists its just a mater of creating a BindingSource with your data (of almost any kind) as its DataSource and then assign it to the controls DataSource!

This can be done either by creating the binding source in code such as

DBListView1.DataSource = new BindingSource(MyData,””);

Or graphically by adding a BindingSource to your form and choosing it as the DataSource for your control in the property inspector.

And then if you need to, you can change the data in the DataSource of the BindingSource as I do in the demo project.

bindingSource1.DataSource = new System.Drawing.Text.InstalledFontCollection().Families;

Have Fun!

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

About the Author

Rabb Moshe Plotkin

United States United States
Co-director of Chabad Student Center @ SUNY New Paltz
Lecturer of Computer Science @ SUNY New Paltz
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 1 Pinmemberadamvsmith14-Jun-10 8:01 
GeneralGood suff - here's a trick to make it a bit better! Pinmembermutantdna29-Apr-10 17:48 
GeneralRe: Good suff - here's a trick to make it a bit better! PinmemberMoshe Plotkin30-Apr-10 2:18 
B"h
 
I haven't used .net2 in years.
WPF which was released with .net3.5 has turned every control into a template based control.
Its almost like the guys at microsoft read this article and said "Hey we can do this for every control."
Thats all I use now days. so I havent looked at this for ages.
GeneralRe: Good suff - here's a trick to make it a bit better! Pinmembermutantdna4-May-10 7:36 
Generalorder Pinmemberdurbich12-Apr-10 4:26 
Generalorder problem Pinmemberdurbich12-Apr-10 4:25 
GeneralRe: order problem PinmemberMoshe Plotkin30-Apr-10 2:17 
GeneralYou forgot to unsubscribe to the old data source event handler ! Pinmemberlcalabrese9-Dec-08 18:54 
QuestionBind Columns? Pinmembermcgrath13-Jun-07 10:03 
AnswerRe: Bind Columns? PinmemberBoinst20-Sep-07 20:45 
GeneralExcellent! Kol Hakavod! PinmemberSimmy78-Jun-06 21:59 

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
Web01 | 2.8.140721.1 | Last Updated 5 Mar 2006
Article Copyright 2006 by Rabb Moshe Plotkin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid