Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Databinding Examples/References/Books

Can anyone recommend any good examples etc for Windows Forms Databinding. I'm looking for realworld small app style examples. Not an F&M multi-tier web enabled cacophony. I want to see something like a detail list form, with an edit screen. Not the standard single form with the klunky hand rolled data control on the bottom.

I'd ideally like to get a solid handle on the very basic stuff before I move on. There seems to be something I'm not seeing with it, although I can't quite put my finger on it. I don't feel like I've "got" it yet.

Geoff Bennett
Wednesday, November 20, 2002

Start with the QuickStart tutorials from the Framework. Then use the DataForm Wizard to build a databound form and look at the generated code. That should get you pretty familiar with all the plumbing.

Mike Gunderloy
Wednesday, November 20, 2002

Thanks for the reply, Mike. I've been through the wizards etc, and I've been all over the small number of articles on the web. The problem is, they all take it from the wizard angle, and they all use the silly data control wannabe to scroll through the records using Position += 1 etc.

I've tried to develop a small contact management application using what I've learned from those examples, and I didn't feel I achieved any leverage at all from databinding. In fact, I think it actually took me longer than it would have if I coded it in an unbound manner. Admittedly (although I don't know how much of an effect this would have), I tried to let Visual Studio's wizards do a lot of the work for me. Maybe rolling it in by hand would be better.

Thanks anyway.

Geoff Bennett
Wednesday, November 20, 2002

Heh-- been programming .NET for so long I didn't understand what you meant when you said "unbound manner." What the heck does that mean??! Manually populating everything? Yuck.

Thursday, November 21, 2002


If you're talking about doing master/detail type stuff then the key lies in defining a DataSet with the master/detail Relation (Typed DataSets allow you to easily set this up - and also wire things up in the forms designer).

Add an instance of your DataSet to the Form from the toolbox and then you can add the DataBindings (it's just doing a control.DataBibdings.Add() in the code-behind) to the master controls. Then, when it comes to the child controls you add them, but *via the relation*. So if you bind a drop-down to "Person.Name" (in the "Contacts" DataSet, say) you could then bind a "detail" control such as a listbox below it to things like "Person.PersonAddress.StreetAddress". Then as if by magic the binding looks after everything for you (the "currency" or current row). You change the item in the drop-down, then the list of addresses is updated to show the correct person's addresses.

In fact, here's a walkthough:


Duncan Smart
Thursday, November 21, 2002

Professional Windows GUI Programming using C# has a chapter on data binding that's quite good.

See .



Ian Lowe
Thursday, November 21, 2002

Thanks for all the help, guys. It's not quite what I'm getting at.

I have a master list of clients. I double click (for instance) on a client, and it opens up the client edit form to that client. That's really where I'm coming from.

I think i've got it nutted at the moment though. I started off thinking that the DataSet/DataAdapter thing was like Delphi's data access (originally being a Delphi programmer) but it's not quite the same. I do love the DataSet though. Best idea in ages.

Geoff Bennett
Sunday, December 1, 2002

Also visit

There is a free, printable chapter available.

Data Binding
Wednesday, January 8, 2003

*  Recent Topics

*  Fog Creek Home