Print Page | Close Window

Last Edited Field

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=946
Printed Date: 13-Mar-2025 at 11:44am


Topic: Last Edited Field
Posted By: BillG
Subject: Last Edited Field
Date Posted: 22-Sep-2008 at 11:33am
I have a form that has fields (textfields, checkboxes, comb boxes etc) hooked up to a Control Binding Manager.  When the user clicks a toolbar button 'Save and Close' the form calls the Save routine of the controller class.
 
Is there any way to tell what was the last edited field on the form at the time the 'Save' button is called?  I would like to take that field out of edit mode programmatically.  Right now, I have the client move off the last edited field but I hate that.
 
If the answer is no, can anyone show me some code to loop through the form and move each field out of edit mode?
 
Bill
 



Replies:
Posted By: davidklitzke
Date Posted: 22-Sep-2008 at 3:22pm
From a two-year old Tech Tip from Ward Bell
 
 
Forcing databinding completion

Some of you may have noticed that clicking on the Save button in the toolstripmenu has different behavior than clicking on a Save button in the form. Editing the property via the textbox and clicking on the Save button in the form saves the edited value. Doing the same thing with the textbox and clicking on the Save button on the toolstripmenu does not.

To fix the behavior of the Save button on the toolstrip menu, there is something you must do to effect the equivalent of a loss of focus when someone clicks the "Save" button in a tool strip.

When I make a change in a textbox and click the Save button in the toolstrip, the textbox does NOT lose focus. This is because the action in the toolbar may be something that should affect the way the text looks (bold it maybe) rather than force the databinding to write through to the data object.

Unfortunately, the Save button's action will save the entity WITHOUT picking up the changed text unless we do something.

That "something" is called "this.validate():" (in C#) or "Me.Validate()" (in VB.Net).

The "this" or "Me" in this case is the Form or UserControl that holds the ToolStrip.

 

 

Sample shown below:

C#:

void SaveAllHandler(object sender, EventArgs e) {
 this.Validate();

// Forces current control to perform databinding as if it lost focus.

 try {
// Save everything
 SaveResult sr = PersistenceManager.DefaultManager.SaveChanges();

VB.NET:

Sub SaveAllHandler(sender As object, e As EventArgs) {
 Me.Validate()

' Forces current control to perform databinding as if it lost focus.

 try {
' Save everything
 Dim sr As SaveResult = PersistenceManager.DefaultManager.SaveChanges()




Print Page | Close Window