473,804 Members | 3,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation and Undo

General question about how WinForms handles undoing a change during a
control's validation, if it does at all.
After a change to a control's value, if the data is determined to be
invalid, then in the control's Validating event handler, setting e.Cancel =
true will prevent the offending control from losing focus until the data in
the control is good.

If the user wants to revert to the original data, say by hitting ESC, does
the form have any kinds of default behaviours for this kind of action (ie:
undoing a change)? Or do I have to program this whole undo process
manually?

This could entail overriding the ProcessCmdKey and looking for ESC, and
storing the value of the control before the control receives focus so I can
reset it after ESC is hit.

I had thought that this was a default behaviour for some reason, but testing
this out reveals this not to be the case for my TextBox.

Are there any suggestions for a better way to implement a simple undo?
Dec 14 '05 #1
10 4353
John,

The TextBox has undo capability, but you don't know how many changes
have been made, so you just can't unwind the undo stack.

Rather, you will have you go to the data source and get the original
value (or, store the original value when binding occurs). That's the only
way you can be sure of the original value.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"John Richardson" <j3*********@no spam.ca> wrote in message
news:uU******** ******@TK2MSFTN GP11.phx.gbl...
General question about how WinForms handles undoing a change during a
control's validation, if it does at all.
After a change to a control's value, if the data is determined to be
invalid, then in the control's Validating event handler, setting e.Cancel
= true will prevent the offending control from losing focus until the data
in the control is good.

If the user wants to revert to the original data, say by hitting ESC, does
the form have any kinds of default behaviours for this kind of action (ie:
undoing a change)? Or do I have to program this whole undo process
manually?

This could entail overriding the ProcessCmdKey and looking for ESC, and
storing the value of the control before the control receives focus so I
can reset it after ESC is hit.

I had thought that this was a default behaviour for some reason, but
testing this out reveals this not to be the case for my TextBox.

Are there any suggestions for a better way to implement a simple undo?

Dec 14 '05 #2
>The TextBox has undo capability

Is this only for a databound context? I looked at the interface for the
textbox and I couldn't see where the previous value of the control would be
stored... and I don't need a whole undo history. That being said, I'll
probably build it myself anyways to give myself some flexibility.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:uF******** *****@tk2msftng p13.phx.gbl...
John,

The TextBox has undo capability, but you don't know how many changes
have been made, so you just can't unwind the undo stack.

Rather, you will have you go to the data source and get the original
value (or, store the original value when binding occurs). That's the only
way you can be sure of the original value.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"John Richardson" <j3*********@no spam.ca> wrote in message
news:uU******** ******@TK2MSFTN GP11.phx.gbl...
General question about how WinForms handles undoing a change during a
control's validation, if it does at all.
After a change to a control's value, if the data is determined to be
invalid, then in the control's Validating event handler, setting e.Cancel
= true will prevent the offending control from losing focus until the
data in the control is good.

If the user wants to revert to the original data, say by hitting ESC,
does the form have any kinds of default behaviours for this kind of
action (ie: undoing a change)? Or do I have to program this whole undo
process manually?

This could entail overriding the ProcessCmdKey and looking for ESC, and
storing the value of the control before the control receives focus so I
can reset it after ESC is hit.

I had thought that this was a default behaviour for some reason, but
testing this out reveals this not to be the case for my TextBox.

Are there any suggestions for a better way to implement a simple undo?


Dec 15 '05 #3
"John Richardson" <j3*********@no spam.ca> a écrit dans le message de news:
O$************* *@TK2MSFTNGP14. phx.gbl...

| >The TextBox has undo capability
|
| Is this only for a databound context? I looked at the interface for the
| textbox and I couldn't see where the previous value of the control would
be
| stored... and I don't need a whole undo history. That being said, I'll
| probably build it myself anyways to give myself some flexibility.

I can't see the previous messages in this thread, has the subject changed ?

In the absence of other replies, can I suggest you look at implementing
IEditableObject in the class whose instances you are editing. If you are
linking to a database table, then I thought that the record datatype had
undo facilities. It is not the job of the edits to maintain undo
information, that is the job of the class supplying the data.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 15 '05 #4
>It is not the job of the edits to maintain undo information, that is the
job of the class supplying the data.
I think that I might disagree with this. I think that there should be 2
levels of editing/undoing: the individual field, and the "row", or more
generally, a set of fields. A typical form interaction will be to load
data, edit various fields, and then indicate that the data should be
saved -> this is the transaction that should be class level.

But, as the user edits a field, the control itself offers a Validation
event, which is hinting at a Transaction at the control level. So, a Field
transaction should be viewed as beginning when the control is focused,
ending when the control is unfocused, and I would think that a cancel should
be implemented by ESC, or some other commonly understood method.

For some reason, I figured this was a default behaviour of the Control
object, but it is not. In my view, this behaviour is fairly natural
assumption... it makes more sense than say the SHIFT-SPACE behaviour on the
datagrid, that is for sure.
"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:uM******** ******@TK2MSFTN GP10.phx.gbl... "John Richardson" <j3*********@no spam.ca> a écrit dans le message de news:
O$************* *@TK2MSFTNGP14. phx.gbl...

| >The TextBox has undo capability
|
| Is this only for a databound context? I looked at the interface for the
| textbox and I couldn't see where the previous value of the control would
be
| stored... and I don't need a whole undo history. That being said, I'll
| probably build it myself anyways to give myself some flexibility.

I can't see the previous messages in this thread, has the subject changed
?

In the absence of other replies, can I suggest you look at implementing
IEditableObject in the class whose instances you are editing. If you are
linking to a database table, then I thought that the record datatype had
undo facilities. It is not the job of the edits to maintain undo
information, that is the job of the class supplying the data.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 15 '05 #5
"John Richardson" <j3*********@no spam.ca> a écrit dans le message de news:
%2************* ***@TK2MSFTNGP0 9.phx.gbl...

| But, as the user edits a field, the control itself offers a Validation
| event, which is hinting at a Transaction at the control level. So, a
Field
| transaction should be viewed as beginning when the control is focused,
| ending when the control is unfocused, and I would think that a cancel
should
| be implemented by ESC, or some other commonly understood method.
|
| For some reason, I figured this was a default behaviour of the Control
| object, but it is not. In my view, this behaviour is fairly natural
| assumption... it makes more sense than say the SHIFT-SPACE behaviour on
the
| datagrid, that is for sure.

FMPOV, the Validating event in the Control class fits very well into the
Model View Presenter framework as it is a response to a user interaction
trying to quit editing a value.

The edit is a means of entering data that will be passed to the underlhying
data member. The Validating event gives the program an opportunity to
interrupt the flow of data to the data member and prompt the edit to refresh
itself to the, as yet unchanged, underlying data member.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 15 '05 #6
I completely agree with what you wrote below. But it doesn't quite address
what I was asking about originially. I was using the Validation event as an
example, but my original post was about how the user can indicate aborting
an edit of an individual field, which would then undo the value -> going
back to the original previous to the edit. In this case, the *standard*
Validation event doesn't apply because the control hasn't lost focus yet.
The user is indicating that a mistake was just made, and the original value
of the field should be restored. Admittedly, this is very subtle, since
it's very similar to just forcing a failed validation procedure.

To continue your Model View Presenter paradigm, it seems useful to have a
kind of UserCancelled message to cause the display of the control to be
reloaded with previous data; it differentiates a user-initiated cancel from
failing a logic test in the Validating handler when the user tries to enter
bad data. If this is in fact a good idea, then I guess I'm surprised that
the general control interface doesn't provide any implicit methods for this.

<Tab> will change focus. Why not <ESC> to revert to the value before focus.
I guess maybe the Form is capturing Esc msgs...
Well, either way, I'll have to code what I want myself.

It's been a fun discussion.

"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:eT******** ******@TK2MSFTN GP11.phx.gbl...
"John Richardson" <j3*********@no spam.ca> a écrit dans le message de news:
%2************* ***@TK2MSFTNGP0 9.phx.gbl...

| But, as the user edits a field, the control itself offers a Validation
| event, which is hinting at a Transaction at the control level. So, a
Field
| transaction should be viewed as beginning when the control is focused,
| ending when the control is unfocused, and I would think that a cancel
should
| be implemented by ESC, or some other commonly understood method.
|
| For some reason, I figured this was a default behaviour of the Control
| object, but it is not. In my view, this behaviour is fairly natural
| assumption... it makes more sense than say the SHIFT-SPACE behaviour on
the
| datagrid, that is for sure.

FMPOV, the Validating event in the Control class fits very well into the
Model View Presenter framework as it is a response to a user interaction
trying to quit editing a value.

The edit is a means of entering data that will be passed to the
underlhying
data member. The Validating event gives the program an opportunity to
interrupt the flow of data to the data member and prompt the edit to
refresh
itself to the, as yet unchanged, underlying data member.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 16 '05 #7
"John Richardson" <j3**********@h otmail.com> a écrit dans le message de
news: OC************* *@TK2MSFTNGP14. phx.gbl...

|I completely agree with what you wrote below. But it doesn't quite address
| what I was asking about originially. I was using the Validation event as
an
| example, but my original post was about how the user can indicate aborting
| an edit of an individual field, which would then undo the value -> going
| back to the original previous to the edit.

| <Tab> will change focus. Why not <ESC> to revert to the value before
focus.
| I guess maybe the Form is capturing Esc msgs...

If you implement IEditableObject in the business object whose properties you
are trying to edit, then pressing the Esc key whilst still in the edit will
revert the value in the edit to that of the underlying property. Is that
what you want ?

| Well, either way, I'll have to code what I want myself.

Not necessarily :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 17 '05 #8
That is precisely what I want, but I realise now that it can only be
acheived with databinding, which is not quite what I want, since I don't use
databinding where I can avoid it. It's interesting, because online
documentation says nothing about relating ESC, IEditableObject , and any
generic control. Most google hits discuss the DataGrid, which has several
special key behaviours defined. If this works for a textbox, I will be a
bit surprised.

Thanks for going the distance.
"Joanna Carter [TeamB]" <jo****@not.for .spam> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...
"John Richardson" <j3**********@h otmail.com> a écrit dans le message de
news: OC************* *@TK2MSFTNGP14. phx.gbl...

|I completely agree with what you wrote below. But it doesn't quite
address
| what I was asking about originially. I was using the Validation event
as
an
| example, but my original post was about how the user can indicate
aborting
| an edit of an individual field, which would then undo the value -> going
| back to the original previous to the edit.

| <Tab> will change focus. Why not <ESC> to revert to the value before
focus.
| I guess maybe the Form is capturing Esc msgs...

If you implement IEditableObject in the business object whose properties
you
are trying to edit, then pressing the Esc key whilst still in the edit
will
revert the value in the edit to that of the underlying property. Is that
what you want ?

| Well, either way, I'll have to code what I want myself.

Not necessarily :-)

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 20 '05 #9
"John Richardson" <j3*********@no spam.ca> a écrit dans le message de news:
eQ************* *@TK2MSFTNGP15. phx.gbl...

John, I must admit, having gone to the trouble to design a good working
BindingList and implementing all the right interfaces to support this
behaviour in a DataGridView, I had expected it to work with the edits as
well.

Surprise, surprise !! Thanks to you, I now need to delve into the inward
parts of the FCL and see why this is not happening; it is a functionality
that my client requires as well.

If you should find the answer before I do, please be good enough to drop me
a note as well as posting it here. my address is my first name at
carterconsultin g, the domain is .org.uk.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 20 '05 #10

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

Similar topics

2
2835
by: R Bolling | last post by:
I am using a routine to check to see if a phone number (PK) has alread been entered, and takes the user to that record if it is found -- as follows: Private Sub Contact_telephone___BeforeUpdate(Cancel As Integer) Dim rs As DAO.Recordset Dim iAns As Integer Set rs = Me.RecordsetClone rs.FindFirst " = '" & Me! & "'" If Not rs.NoMatch Then
2
320
by: Tony Williams | last post by:
I am validating two text boxes to make sure they contain data. I have use Is Not Null in the Validation Property of the control but it doesn't seem to work. The Help shows Validation with code. How do I write the rule to check the user has completed the control? TIA Tony Williams
2
3382
by: Bart Lateur | last post by:
I'd like to have validation of the inputted text, in a form textbox. I want to give the user the option to try again, or to cancel out after which the textbox is either cleared or restored. I just don't succeed. In the before_update event, I can cancel out the change, after which the input box keeps the focus. Fine. But I can't change the value for the input box in case he wants to cancel out, it gives an error. I can restore or clear...
3
3169
by: GoogleEyeJoe | last post by:
Dear ladies and gents, I'm trying to determine whether the .NET Framework implements a means of transactional processing without the need for a database. Essentially, I'd like to enlist light-weight portable business objects within transactions so that that have the ability to roll-back if the client of the object wishes to undo any changes made. For example, if I had a, let's say for sake of simplicity, a person class that had two...
4
1597
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, Does vb2005 have a built-in UnDo feature / object for applications so that I can undo actions like other windows apps? Or do I have to write my own UnDo routine? If vb2005 does have a builtin Undo feature / object / command -- how to implement it? invoke it? If there is no builtin undo feature - is there a recommended way to write an
5
1576
by: billa856 | last post by:
Hi, My project is in MS Access. In that one form of data entry I am using this code for validation of field. Private Sub CustomerCode_Combo_LostFocus() If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then strMsg = "You must select Customer Code from the ComboBox." strTitle = "CustomerCode Required" intStyle = vbOKOnly MsgBox strMsg, intStyle, strTitle Me.CustomerCode_Combo.Undo
0
2095
by: wizard of oz | last post by:
Hi all, I'm extending an Abstract Styled Document associated with a JTextPanel to implement a syntax highlighting editor. This is all working just fine - except for undo / redo. The problem is that the undo manager is recording my highlighting that occurs as a result of keystrokes. So whenever the user performs undo, the last operation (a colour highlight operation) is undone. Since I need to refresh the highlighting when the undo is...
1
1652
by: Jeremy | last post by:
I'm working on an application that does some DOM manipulation. I want to add a mechanism for "Undo" so that the user can revert to the previous state after performing a mistaken action. Simple idea, not necessarily simple to implement. My first idea for this is to use closures and an array that tracks the inverse of the user's actions. Here's a simple example in which the user can only remove DOM nodes and then undo the removal...
18
6235
by: ChipR | last post by:
I have a text box with a validation rule and validation text. When entering a new record, if I put in invalid text, the validation text is displayed in a message box, but after clicking OK, another message box is displayed with: ----------- myApplication (i bubble icon) The value violates the validation rule for the field or record. For example, you might have changed a validation rule without verifying whether the existing data matches...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.