Live Chat Icon For mobile
Live Chat Icon

How can I have a column of bitmaps in a DataGrid

Platform: WinForms| Category: 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 bitmap in the cell; size it to fit the cell bounds, size it proportionally to fit the cell bounds, and draw it with it’s 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.

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.