How do you load an image from a URL and then put it into DataGridView's cell (not Column header)? The rows which include the images will be added to the view at runtime based on a search from web service. Cannot find an answer for this specific purpose... Help!
First I tried using PictureBox. When events are received from web service, I will loop thru result to add rows, each of which includes an image.
// Add image
System.Windows.Forms.PictureBox picEventImage = new System.Windows.Forms.PictureBox();
picEventImage.Image = global::MyEventfulQuery.Properties.Resources.defaultImage;
picEventImage.ImageLocation = Event.ImageUrl;
this.dgvEventsView.Controls.Add(picEventImage);
picEventImage.Location = this.dgvEventsView.GetCellDisplayRectangle(1, i, true).Location;
Even though the image loads perfectly, it looks disconnected from the view, i.e. images does not move when I scroll, and when refreshing the view with new data, images just hang around... bad.
So I tried tips from other postings:
Image image = Image.FromFile(Event.ImageUrl);
DataGridViewImageCell imageCell = new DataGridViewImageCell();
imageCell.Value = image;
this.dgvEventsView[1, i] = imageCell;
But I got an error saying "URI formats are not supported."
- Am I using Image incorrectly?
- Is there another class that I can use for URL image instead of Image?
- Or do I have no choice but to create a custom control (which contains a PictureBox) to add to the DataGridView cell?