Click here to Skip to main content
15,887,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a small WinForm project in VS 2010 C#, I created a Customer class with two properties (CusID & CusNm). And, I drew a ComboBox and a TextBox on a panel container drawn on the Form, (ComboBox for CusNm & TextBox from the CusID). I used two binding objects to bind the customer1.CusNm & customer1.CusID properties with the ComboBox and TextBox respectively, the two bindings went well, and the values of the customer.CusID and customer1.CusNm normally appear on the TextBox and the Combobox. But when I try to assign a value for the customer1.CusID in the code ( like:
customer1.CustID = 100; ) , the new value doesn't get reflected on the TextBox, and the old value (which is: 0 ) still stays in the TextBox. So, how can I make the TextBox get updated with the new value, when I assign it using C# code?

Thank you so much

What I have tried:

I reviewed the binding, but everything seems fine..

<br />
binding bdCusID = new binding ("Text", customer1,"CusID");<br />
TextBox1.bindings.add(bdCusID);<br />
customer1.CustID = 100; <br />
<pre lang="c#"></pre>
Posted
Updated 19-Jan-20 5:12am
v2

You need to implement INotifyPropertyChanged in your Customer class.

Here you find an example how to do it: INotifyPropertyChanged Interface (System.ComponentModel) | Microsoft Docs[^]
 
Share this answer
 
Comments
Mohammad Abdullaha 25-Jan-20 6:58am    
Thank you, friend. I followed the way of the example explained in the page with the link you provided, and everything went well..
Use the SelectedIndex or SelectItem to "select" in a combo box (i.e. list control).

ComboBox.SelectedIndex Property (System.Windows.Forms) | Microsoft Docs[^]
 
Share this answer
 
Comments
Mohammad Abdullaha 17-Jan-20 0:40am    
But, I want to it for TextBox. When I change the value of the customer1.CusID from the Code, TextBox is supposed to get updated with the new value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900