1

I would like to have a combo box that contains 3 small Icons or Bitmaps, I dont mind which.

I have tried the following code to add 1 image:

DataGridViewComboBoxColumn statusColumn = new DataGridViewComboBoxColumn();
Icon greenIcon = new Icon("../../Resources/green_tick.ico");
Bitmap bitmapGreen = greenIcon.ToBitmap();
object itemtoadd = bitmapGreen;
statusColumn.Items.Add(itemtoadd);

All that happens is it has the Type name in the combobox and an execption is thrown.

Can anyone help me display an image in a combo box?

Mark Kram
  • 5,672
  • 7
  • 51
  • 70
maffo
  • 1,393
  • 4
  • 18
  • 35
  • This is Windows.Forms is suppose? I don't think the default ComboBox supports images as items – kev Dec 14 '11 at 15:50
  • @kev -- Yes its for a form. I have renamed my question so ppl know. – maffo Dec 14 '11 at 16:06
  • Check this thread: http://stackoverflow.com/questions/1232861/combo-box-with-icons-in-windows-forms This should also work for a DataGridViewComboBoxColumn – kev Dec 15 '11 at 08:35

1 Answers1

0

You have to wire up a Drawitem event handler in the EditingContolShowing event after casting the sender to ComboBox.

In Drawitem, you then use Graphics GDI method DrawImage to draw your bitmap.

Sadly the datagridviewcomboboxcolumn doesn't have the inherent capabilities of a forms listcontrol.