Bindings are fun

I can't believe it: I'm actually using data bound controls. Will wonders never cease?

This is a surprise because I always hated data bound controls in VB6. They worked well enough for simple things, but they just didn't have a lot of flexibility. I always found them to be one of those features that's great if you're willing to buy into the one true method of application development described in Microsoft's tutorials, but not to nice otherwise. Thus I tended not to use them too much. In fact, I pretty much only used data controls bound to data grids as a way of browsing data sets. I handled everything else in code.

However, I was pleasantly surprised by data binding with ADO.NET. For starters, the fact that ADO.NET data sets are disconnected eliminates the inflexibility over control of updates. This was a big improvement in and of itself.

The big one, though, was when I discovered the System.Windows.Forms.Binding class, which is what actually handles binding a control property to a data set field. It turns out that this class has two handy events: Format and Parse. These are raised when a control is populated from the data set and when the control value is propogated back to the data respectively.

Using these two events allowed me to do one of my favorite tricks with bound controls: condensing an object into a combo box. So, for example, I can have an EmployeeID field and bind a combo box to that, but have the box display the employee's full name, department, etc. It's actually quite nice. Things weren't nearly this nice in the bad old days of VB6, and so I am once again a happy Windows programmer.

You can reply to this entry by leaving a comment below. You can send TrackBack pings to this URL. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.