In a DataGridView bound to a DataView, where cells in a column will contain one of two images from an ImageList (e.g. a green ‘online’ image or a red ‘offline’ image), how can you sum the number of occurences of each image when iterating through the DataGridView’s rows?
The Value and FormattedValue properties of DataGridViewImageCell return different references even though the entries in the underlying DataTable were created by referencing the same Image from the ImageList.
So rather than it counting 4 occurences of ‘online’ and 6 occurences of ‘offline’, I’m getting 10 occurences of alledgedly different images.
Given the description, the best I can suggest is to manually track the image key/index in the .Tag of the cell, and then run your distinct count on the .Tag. Alternatively, if you also have the data in a list/collection, count the data from the original source.
[update following reply] Since the data is data-bound, you should be able to iterate the
.Rowsof theDataGridView, obtaining the.DataBoundItemof each. Then for each underlying object, you should be able to obtain the actual property value usingTypeDescriptor:That any help?