DataGridView Image Column (Data bound) VS2008 or higher
This project demonstrates one method to display images in a DataGridView where the underlying data is data bound.
To be perfectly honest I have only used this method with small sets of data, meaning either several columns with say a couple thousand rows or many columns with a hundred rows so depending on your return data table size performance may be an issue.
The function SimulateLoadingTableFromDatabase does as the name implies. In a normal application you would probably use a connection and command to load a data set or data table. So in this case I create a DataTable with three data columns. The caller then adds a new data column which is of type byte used to display icons in the first column of the DataGridView.
Since the newly added column is does not belong to the original data source we must set the value for each column based on the value of a column which was from the original data source which is done in DoIconImages. When a row is updated DoIconImages updates the icon.
What you do not see that is important.
The columns for DataGridView1 are done via the chevron (arrow in the upper right corner of the DataGridView in design mode). Column type and the data property are set.
Each image is marked as embedded resource and if not the code which reads the icons will fail with an empty stream in the ReadToEnd method.
Caveats
The class DataGridViewIcons is declared in the form but could be declared else in another location.
The BindingSource is not needed, I have a habit of using them and if you care not to use a BindingSource and the language extensions you can simply use the DataTable which was assigned to the BindingSource then when you need access to the DataTable either make it accessible to where it is needed or cast the DataGridView data source to a DataTable and then use it.
Example
Last edited by kareninstructor; Jul 20th, 2011 at 12:57 PM.