Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Data binding control to object property

Posted on 2004-08-20
5
Medium Priority
?
288 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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