473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refreshing control if entity is re-loaded

Winforms appl creates customer edit form containing textboxes using

Customer dataSource = Northwind.Customers.GetByName("Airbus");
MaskedTextBox tb = new MaskedTextBox();
Binding binding = new Binding("Text", dataSource, "Phone");
binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
binding.FormattingEnabled = true;
tb.DataBindings.Add(binding);

There is revert button in form which discards edited fields read original
values from database.
For this I use the following code:

// Re-Get original value
dataSource = Northwind.Customers.GetByName("Airbus");

However edit form still shows edited phone number.

How to force MaskedTextBox or other Control to update its contents if bound
entity (customer) is re-loaded form database ?

Andrus.

Sep 4 '08 #1
3 1994

"Andrus" <ko********@hot.eewrote in message
news:ON**************@TK2MSFTNGP06.phx.gbl...
Winforms appl creates customer edit form containing textboxes using

Customer dataSource = Northwind.Customers.GetByName("Airbus");
MaskedTextBox tb = new MaskedTextBox();
Binding binding = new Binding("Text", dataSource, "Phone");
binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
binding.FormattingEnabled = true;
tb.DataBindings.Add(binding);

There is revert button in form which discards edited fields read original
values from database.
For this I use the following code:

// Re-Get original value
dataSource = Northwind.Customers.GetByName("Airbus");

However edit form still shows edited phone number.
That's because you didn't change the actual data source. You've only changed
the value of your own variable (or field) dataSource, which is of type
"reference to Customer". It no longer points to the old instance of
Customer, but your binding still does.

Instead, try binding your controls to a BindingSource, and changing its
DataSource property.
Sep 5 '08 #2
Pavel,
Instead, try binding your controls to a BindingSource, and changing its
DataSource property.
Thank you.
I switched to BindingSource:

var BindingSource = new BindingSource();
BindingSource.DataSource = Customer;
Binding binding = new Binding("Text", BindingSource, "Phone");
binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
binding.FormattingEnabled = true;
control.DataBindings.Add(binding);

To revert changes I use

BindingSource.DataSource = OriginalCustomer;
BindingSource.ResetBindings(false);

Now control show old value properly after revert.

When another value is entered to TextBox after revert, this value is no more
written to customer property.
It seems that bindings are lost.
How to set DataSource so that bindings are not lost ?

Andrus.

Sep 5 '08 #3
"Andrus" <ko********@hot.eewrote in message
news:uo**************@TK2MSFTNGP06.phx.gbl...
Pavel,
>Instead, try binding your controls to a BindingSource, and changing its
DataSource property.

Thank you.
I switched to BindingSource:

var BindingSource = new BindingSource();
BindingSource.DataSource = Customer;
Binding binding = new Binding("Text", BindingSource, "Phone");
binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
binding.FormattingEnabled = true;
control.DataBindings.Add(binding);

To revert changes I use

BindingSource.DataSource = OriginalCustomer;
BindingSource.ResetBindings(false);

Now control show old value properly after revert.

When another value is entered to TextBox after revert, this value is no
more written to customer property.
It seems that bindings are lost.
No, the values are written. They are just written to the instance of
Customer that OriginalCustomer references, and I guess that you're looking
at the other one.

Can you please show where Customer and OriginalCustomer come from, and how
do you use them? In particular, how you check that the value is not written?
Sep 5 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
4987
by: Philo Del Middleston | last post by:
I've been searching, but apparently not phrasing my search right, so I'm going to float a question out here in the meantime... I'm wondering how to go about refreshing the content of a control...
1
3196
by: Mark Johnson | last post by:
I wonder if anyone has a solution? I wanted to use the web browser control as a 'zoom' box for a smaller textbox. I can format in the control, and save whatever formatting as HTML code back to the...
1
1627
by: Microsoft | last post by:
I am having a problem where the gui is not refreshing. I have an ActiveX control that displays output from a ccd camera on the main gui. The control is embedded in a usercontrol. The usercontrol...
5
3472
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
2
1285
by: jesl | last post by:
Group, I have created a User Control with the property "Html" of type string. If I declare this control on an ASPX page with the value "<b>This is an entity: &lt;</b>" for the property "Html", the...
2
2474
by: Ben | last post by:
Hi, One ASP.NET transactional page conducts a long transaction in a button click function. I want to display the transaction progress info in label control without refreshing page. It is...
9
4410
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in a...
0
2048
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in...
0
1275
by: jagsusa | last post by:
Hi All I need to assign the current user to the people picker control in my custom ASPX page which I am planing to host in sharepoint (WSS) . I was trying on these lines but without success. ...
0
1008
by: jagsusa | last post by:
Hi In the following code I could trace out the current logged in user but still the control is blank for me any idea ?? userPicker = new PeopleEditor(); SPUser user = ipsWeb.CurrentUser;...
0
7213
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
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
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,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.