473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

INotifyPropertyChanged and programmatic changes to GUI controls issue

5
Okay say we have a class that implements INotifyPropertyChanged and a property that has code in the setter to raise the PropertyChanged event. On the GUI side we have a text box with the code:

txtFirst.DataBindings.Add("Text", p, "FirstName", True) Where p is a Person object and FirstName is the property that raises the PropertyChanged event.

It works perfectly when I programmatically change the object's property or using the application, change the textbox's text. The problem is if I try to change the textbox's text programmatically.

Consider this example:

Saying txtFirst.Text = "Joe" (when it was previously blank) does not update the object's FirstName property. But if I write the following code it does:

txtFirst.Focus()
txtFirst.Text = "Joe"
txtLast.Focus()

Basically I emulated what a person using the program would do. Click on the textbox. Enter text, and then click on the next text box. It seems the loss of focus kicks off the PropertyChanged event. But this seems like a non-elegant solution. Any ideas on what I am doing wrong? Or is this what I have to do to get this to work

I'm using VB.Net 3.5 SP1 and a Smart Device project (thus, win forms). I'm trying to implement a n-tier program seperating the GUI code from the Logic and Logic form the data. Thus I don't want in the GUI to change the properties of the logic objects. I'd rather change the GUI control and have that due to 2-way binding update the logic object.

Thanks for your help!
Jun 17 '09 #1
2 2921
tlhintoq
3,525 Expert 2GB
It seems the loss of focus kicks off the PropertyChanged event. But this seems like a non-elegant solution.
Would you want to change the property (and thus raise the PropertyChanged event) on every keystroke by the user in the textbox? That seem ugly:

J <PropertyChangedEvent>
o <PropertyChangedEvent>
e <PropertyChangedEvent>
{space} <PropertyChangedEvent>
S <PropertyChangedEvent>
m <PropertyChangedEvent>
i <PropertyChangedEvent>
t <PropertyChangedEvent>
h <PropertyChangedEvent>

How about a local property in the form? Changing it changes the text of the textbox as well as your p object property?

Expand|Select|Wrap|Line Numbers
  1. string FirstName
  2. {
  3. get
  4. {
  5.    return p.FirstName;
  6. }
  7. set
  8. {
  9.    txtFirst.Text = value;
  10.    p.FirstName = value;
  11. }
  12. }
Jun 17 '09 #2
nelmr
5
I had a brain fart apparently. I have nothing against programmatically setting p.FirstName = Joe instead of the txtFirst.Text = Joe.

Thanks for the answer though as it makes sense why PropertyChanged does not fire when I set the text. Thanks.
Jun 17 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Greg Allen | last post by:
I know this has been discussed before, and have found some documentation about it on the web. But nothing has fixed my problem. I am running the 1.1 .NET framework, SP1. I have a web...
4
by: Betina | last post by:
Hi, I've created a Person-Object which implemts INotifyPropertyChanged. This Person-Object contains an Address-Object which implements INotifyPropertyChanged too. Then I create a...
2
by: matt.delvecchio | last post by:
hello, i have a user control that works great, when its used as a design-time controls. however, when i try to use it as a programmtic control, im running into troubles. the control is pretty...
1
by: Hardeek Thakkar | last post by:
Dear friends, In my current project I am using the CustomCollections with the help of BindingList<Tgeneric class to store the database records instead using DataSet objects as offline database...
1
by: Gokul | last post by:
Hi, I'm using indexed properties in an object which acts as the binding source. How can I implement INotifyPropertyChanged for that object so that when the indexed property is updated, binding...
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { //...
2
by: John Greenwood | last post by:
Hi, I'm not sure if i'm misunderstanding how INotifyPropertyChanged should work but it's not working as I expected. I have a sample program with a very simple 'Customer' class with three...
5
by: vovan | last post by:
I have set of controls (Textboxes, checkboxes etc) along with the Grid on Windows Form. I use BindingSource to populate both Grid and the set of Controls. User selects the record in the grid and...
0
by: Gerrit | last post by:
Hello, On http://msdn2.microsoft.com/en-us/library/ms184414.aspx is an example of the implementation of INotifyPropertyChanged Interface. I work with the C# example. I have tried this sample,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.