472,964 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1981

"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
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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.