Format Data-Bound Fields

Problem

You want to apply specific formatting to certain fields in a database (for example, display numbers as currency strings, convert fixed constants to more descriptive text, and so on).

Solution

React to the Parse and Format data binding events, which allow you to "translate" values as they are retrieved from the DataTable and inserted back into the DataTable.

Discussion

In earlier versions of Microsoft Visual Basic, you had little ability to customize raw database values when displaying them through data binding. The data binding provided by Windows Forms improves on this situation with the Parse and Format events. The Format event fires just before a data value is displayed.

It allows you to format the information for ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.