Solved

PictureBox DataBinding

Posted on 2008-09-29
3
3,094 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22602933
which ado driver do you use?
0
 
LVL 8

Author Comment

by:mac-will
ID: 22604568
Hi,

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

Accepted Solution

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
need to convert function to c# 5 43
C# DataTable (in memory) vs SQL Lookups 4 35
Nested forach loop to linq 3 28
C# LINQ 5 24
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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