Solved

PictureBox DataBinding

Posted on 2008-09-29
3
3,027 Views
Last Modified: 2012-05-05
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
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);

}

Open in new window

0
Comment
Question by:mac-will
  • 2
3 Comments
 
LVL 37

Expert Comment

by:momi_sabag
Comment Utility
which ado driver do you use?
0
 
LVL 8

Author Comment

by:mac-will
Comment Utility
Hi,

I use the DB2 .NET driver.
Thanks
MAC
0
 
LVL 8

Accepted Solution

by:
mac-will earned 0 total points
Comment Utility
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

   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);

        }
 

}

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now