New Posts New Posts RSS Feed: Last Edited Field
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Last Edited Field

 Post Reply Post Reply
Author
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Topic: Last Edited Field
    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
 
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post 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()



Edited by davidklitzke - 22-Sep-2008 at 3:23pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down