PictureBox Binding

  • Thread starter Thread starter Jesse
  • Start date Start date
J

Jesse

Hi All,

I've been working on a form that has several bound
controls that all link to one table in a dataset. In the
table, there is a column for the filename of jpeg images
related to each record. I have a combobox which displays
the key for each record so that the user can select an
item and all the other controls update. So far i have
the combobox, a label and a textbox all bound and working
correctly when a user selects an item. I have a
pictureBox on the form however that i wish to be bound to
the filename field for the specific row. Does anybody
know how to do this?

Thanks in advance,
Jesse

ps. I don't want to put a BLOB field in the database for
the images and do it that way.
 
Hi Jesse,

You have to streamread it to get it in your picturebox (even if you use a
blobfield)

I think that you can not bind real in a productive way.

So in my opinion you only can use the changing events to read it.

But just my thought about it

Cor
 
Thanks cor for your suggestions.

I have found a way though which does not involve streams
(because i didn't want to use BLOB fields).

What i have done is this (if you wish to know):

'Members
Private WithEvents m_PictureBinding As Binding
Private currentImageFile As String

'This binds the pictureBox (picBikePics)
Private Sub BindControls()
m_PictureBinding = New Binding("Image", dsAll.Tables
(0), "Filename")
picBikePics.DataBindings.Add(m_PictureBinding)
End Sub

'This method gets fired everytime the above Binding
object (m_PictureBinding) row is changed and is used to
place the correct value back in the database before
continuing. (In my case, i don't want to change the
database field at all so i set it to what it was
originally which i set in the method "Format") Private
Sub m_PictureBinding_Parse(ByVal sender As Object, ByVal
e As System.Windows.Forms.ConvertEventArgs) Handles
m_PictureBinding.Parse

e.Value = currentImageFile

End Sub

'This method gets fired everytime that same object is
changed but is used to make sure the value going into the
control from the database is of the right type for the
Image property on the control. So i have to convert the
filename string to an Image object.
Private Sub PictureBox_Format(ByVal sender As Object,
ByVal e As ConvertEventArgs) Handles
m_PictureBinding.Format

currentImageFile = CStr(e.Value)
e.Value = Image.FromFile(CStr(e.Value))

End Sub

Anyways, thanks again.
Hope u got something out of it. I did.

Jesse
 
Hi Jesse,

Although I never used the event you are using, it was the solution I was
thinking on when I saw your problem. (Not that I would do it that way, but
in the way that you are making your program I would)

(Sometimes I see answers people telling this, and I do not believe that is
true, but you can trust me that is something I do not do).

Cor
 
Back
Top