Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I create a column of bitmaps in a DataGrid?

You can derive a custom columnstyle and override its Paint method to draw the image. Here are both C# and VB.Net samples.

The Paint override offers three ways to draw the bimap in the cell; size it to fit the cell bounds, size it proportionally to fit the cell bounds, and draw it with its original size (clipping the bitmap to fit in the cell bounds). In the sample, the DataGrid is anchored on all four sides, so as you size the form, the DataGrid sizes as well. The dataGrid1_Resized event is handled to dynamically change the PreferredRowHeight and PreferredColumnWidth so the cells occupy all of the DataGrid's client area. So as you size the form the grid cells size also so you can easily see the bitmaps.

Contributed from George Shepherd's Windows Forms FAQ