0

A row, in a data table, iscalled FirstImage contains a url to an image file on a web server. I am trying to bind the data of this row to the image source of the picture box.

My current code:

For Each row As DataRow In ListData.Rows
    Dim ImageDecode = ser.Deserialize(Of PropertyImage())(row("Images"))
    row("FirstImage") = "http://rental.joshblease.co.uk/propertyimages/" & ImageDecode(0).Image
    'Returns http://rental.joshblease.co.uk/propertyimages/image1.jpg
Next row
TxtListName.DataBindings.Add("Text", ListData, "Name")
TxtListSlug.DataBindings.Add("Text", ListData, "Slug")
TxtListCreated.DataBindings.Add("Text", ListData, "Created")
ImgListItem.DataBindings.Add("Image", ListData, "FirstImage", True)
DataRepeater1.DataSource = ListData

But at the moment, the image is still blank. I have tried entering the location into a hidden textbox and copying the data over, but I can;t figure out how to use the controls in a data repeater.

This was the experimental copy from a hidden text box code:

If Me.DataRepeater1.ItemCount > 0 Then
    Dim n As Integer = Me.DataRepeater1.ItemCount
    For i As Integer = 1 To n
        Me.DataRepeater1.CurrentItemIndex = i - 1
        Dim item = Me.DataRepeater1.CurrentItem
        item.Controls("ImgListItem").ImageLocation = item.Controls("TxtImageLocation").Text
    Next
End If
Blease
  • 1,380
  • 4
  • 38
  • 64

2 Answers2

1

Simply add Picture Box property ImageLocation

ImgListItem.DataBindings.Add("ImageLocation", ListData, "FirstImage", True)
Siz S
  • 846
  • 3
  • 8
  • 27
0

The databinding for the image expects binary image data and in this case your passing it a string. What we can do is convert the image location into a format the binding can understand. Take a look at this link C# Code Snippet - Download Image from URL. Then once you have the image in memory, you will be able to bind it to your PictureBox.

Also, keep in mind that the simplest way shown in this answer would not work for you since URIs are not supported by the BitMap class.

Community
  • 1
  • 1
alstonp
  • 700
  • 6
  • 25