O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Bind an Image Field to a PictureBox

Problem

You want to bind a PictureBox to a field that contains binary image data.

Solution

React to the Format data-binding event, and convert the binary data to an Image object.

Discussion

You can use data binding to bind any property from almost any control to a database field, including the Image property from the PictureBox control. However, the Image property requires an Image object—not just a byte array. Therefore, you need to perform some conversion to translate the binary data into an Image object.

You can use data-binding events to execute this conversion logic automatically. All you need to do is react to the Format event (first introduced in recipe Format Data-Bound Fields) and create a new Image object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required