Question : PictureBox DataBinding

Hello,

I am trying to DataBind a PictureBox with a stored BLOB image in a DB2 database.

I am able to bind the image using a Binding object as seen in the code below.

My problem is the datasource HasChanged() property is always true even if I don't change the image?

Any idea as to how I can fix this?

Thanks for any help.

MAC
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
ON_LOAD:
Binding binding = new Binding("Image", myRecord.Tables[0], "IMAGE", true);
this.pictureBox1.DataBindings.Add(binding);
 
 
 
 
ON_IMAGE_CHANGE:
 
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "JPEG files|*.jpg|Bitmap files|*.bmp|GIF files|*.gif|All files|*";
DialogResult mResult = openFileDialog1.ShowDialog(this);
 
if (mResult == DialogResult.OK)
{
    myImageFile = openFileDialog1.FileName;
    this.pictureBox1.Image = Image.FromFile(myImageFile);
}

Answer : PictureBox DataBinding

I found my own solution.  I've posted it below for anyone who might find this useful:



You need to have an ImageChanged event.  Make a new class
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
   class MyPictureBox : PictureBox
    {
 
        public event EventHandler ImageChanged;
 
        //MUST USE NEW BECASUSE PictureBox.Image is not virtual
        public new Image Image
        {
            get
            {
                return base.Image;
            }
            set
            {
                bool imageChanged = base.Image != value;
 
                base.Image = value;
               
                if (imageChanged)
                {
                    this.OnImageChanged(new EventArgs());
                }
            }
        }
 
        protected virtual void OnImageChanged(EventArgs e)
        {
            ImageChanged(this, e);
        }
 
}
Random Solutions  
 
programming4us programming4us