I am using a DataGridView with a DataGridViewComboBoxColumn , and I need to add icons to the left of the combobox elements. I am currently using the EditingControlShowing event along with the ComboBox.DrawItem event, for example:
private void pFiles_dgvFiles_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control is ComboBox) { ComboBox cb = (ComboBox)e.Control; cb.DrawMode = DrawMode.OwnerDrawFixed; cb.DrawItem -= combobox1_DrawItem; cb.DrawItem += combobox1_DrawItem; } } private void combobox1_DrawItem(object sender, DrawItemEventArgs e) {
The problem is that the icons are displayed only as long as the cell is in edit mode. As soon as I click somewhere outside the cell, the CellEndEdit event fires and the cell redraws (without icon).
I tried to use the DataGridView.CellPainting event to solve this problem, but this causes the DataGridViewComboBoxColumn drop-down button to disappear.
Any ideas on how to draw an icon after the user has finished editing the cell?
source share