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;
}