Solved

Data binding control to object property

Posted on 2004-08-20
5
285 Views
Last Modified: 2011-09-20
I have a custom object with several properties.  When I bind the controls (e.g. textbox's text property) to a property of the object, it works fine.  However, when I update the object in code (change the properties programmatically), the changes are not reflected in the bound controls.  Is there a way to cause the changes to the property to be propagated to the controls?
0
Comment
Question by:Jetgunner
[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
  • 4
5 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 11854081
In you custom object you need this code:

  public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

and when you change a property (e.g. MyProperty), you raise a PropertyChanged event:

    private object myProperty;
    public object MyProperty
    {
      get { return myProperty; }
      set
      {
        if(myProperty!=value)
        {
          myProperty = value;

          if(PropertyChanged!=null)
            PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("MyProperty"));
        }
      }
    }
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11854104
Oops!  I didn't realize that I was in VB... give the points to anyone that can convert that :)
0
 

Author Comment

by:Jetgunner
ID: 11854480
I added that code to my application (in vb of course).  When I trace through the app, I can see that the PropertyChanged  event does get raised when I change a property, but that doesn't seem to change the bound fields.
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 125 total points
ID: 11855300
Can you give this a try?  Change your code:

  public event System.EventHandler MyPropertyChanged;

And then call:

  if(MyPropertyChanged!=null)
     MyPropertyChanged(this, new System.EventArgs());
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11855305
If you property is called "CustomProperty1", you must call the event "CustomProperty1Changed"
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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