How to Copy the Image in a GridView's Cell
Environment
Product Version | Product | Author |
---|---|---|
2021.2.511 | RadGridView | Desislava Yordanova |
Description
The copy functionality, that RadGridView offers, supports three formats: Text, HTML, CommaSeparatedValue. The internal copy implementation uses the Clipboard.SetDataObject method where the cell's content is extracted in the supported formats. If you store Bitmap values in the cells from the GridViewImageColumn, this value is stored as "System.Drawing.Bitmap" which is the string representation of the type stored in the cell's Value.
This article demonstrates how to achieve copy image functionality in RadGridView and thus to be able to paste it to another application, e.g. MS Excel:
Solution
This requires implementing additional functionality and overriding the default Copy method logic. The Clipboard.SetImage method is suitable for this case as it clears the Clipboard and then adds an Image in the Bitmap format.
Do not forget to replace the default RadGridView with the custom class (CustomGrid) in the InitializeComponent method.