0

I ahve a dgv inside a winform and i want to display an image from the dgv image column inside a combo box drop down list.

i can add other values within the dgv to the combobox:

     var cbString = dgvLineSymbols.Rows[i].Cells["LINE_NAME"].Value.ToString();
     if (cbString != "")
     {
        cbAllSymbols.Items.Add(dgvLineSymbols.Rows[i].Cells["LINE_NAME"].Value.ToString());
     }

if i try adding the value of the image column i get text describing the image as a bitmap.

Ive tried a bunch of things but there isnt a lot of information available on this one.

This was my most hopeful attempt but still did not work, also this required additional dll's being loaded and was causing errors elsewhere in my application.

 System.Windows.Controls.Image theImage = new System.Windows.Controls.Image();

          BitmapImage bitmap = new BitmapImage();
          MemoryStream strm = new MemoryStream();
          strm.Write(bytearr, 0, bytearr.Length);
          bitmap.BeginInit();
          bitmap.StreamSource = strm;
          bitmap.EndInit();
          theImage.Source = bitmap;

There must be an easier way to achieve this considering how straightforward it is to add an image to a dgv:

         if (File.Exists(file))
         {
            Bitmap img;
            img = new Bitmap(@"" + file);
            dgvLineSymbols.Columns[1].Width = 100;
            dgvLineSymbols.Rows[i].Cells[1].Value = img;
         }
  • is it windows data grid or web data grid? – Amit Verma Jul 17 '21 at 06:21
  • windows form sorry should of been clear –  Jul 17 '21 at 21:38
  • I am confident, there is no “built-in” mechanism for the `DataGridViewComboBoxCell` to include an image along with the text. I am pretty sure you will need to roll-your-own or look for a third-party library that may have this functionality. Granted you can add an “image” to a `DataGridViewImageCell`, but that is different cell type from a `DataGridViewComboBoxCell`. – JohnG Jul 18 '21 at 00:29

0 Answers0