jkdt0077
asked on
Displaying image in datagrid from URL stored in database
Hi
The problem is pretty much as the title suggests. This might be fairly easy but I am just starting out with vb.net. I have a datagridview displaying several rows. In one column is an image url. I would like this image to be displayed for each row as part of the datagrid. Is this possible?
Thanks,
Dan
The problem is pretty much as the title suggests. This might be fairly easy but I am just starting out with vb.net. I have a datagridview displaying several rows. In one column is an image url. I would like this image to be displayed for each row as part of the datagrid. Is this possible?
Thanks,
Dan
woops. declared colIndex, and didn't use it. oh well, hopefully you get the idea...
oh, and if you want to read it from a file then you could use:
If e.ColumnIndex = colIndex Then e.Value = Image.FromFile("c:\image.g if")
oh, and if you want to read it from a file then you could use:
If e.ColumnIndex = colIndex Then e.Value = Image.FromFile("c:\image.g
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
Thanks for that, Ive not tried it yet as Im away until this evening. I will try it as soon as I get back and let you know how it goes.
Thanks,
Dan
Thanks for that, Ive not tried it yet as Im away until this evening. I will try it as soon as I get back and let you know how it goes.
Thanks,
Dan
...add an image column after the data is loaded in the datagridview:
Me.DataGridView1.DataSourc
Dim myImageColumn As New System.Windows.Forms.DataG
myImageColumn.HeaderText = "MyImage"
myImageColumn.Name = "MyImage"
Me.DataGridView1.Columns.A
...load an image on the cell formatting event
Private Sub DataGridView1_CellFormatti
' you would probably want to figure out what cell value has your url (based on what row you are on), and
' set this here.
dim imageURL As String = "http:/server/image.gif"
' change this to where the image column ends up...or figure out the header name or something to be more dynamic
Dim colIndex As Integer = 8
' if using true URL, create webclient to read the image
Dim myWebClient As New System.Net.WebClient
' load it up
If e.ColumnIndex = 8 Then e.Value = Image.FromStream(myWebClie
End Sub