473,651 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - Desktop App: Windows form, canceling changes in a control.

TonFrere
14 New Member
Hello,
I'm building a solution using Visual Studio Windows Forms and I'm coding in C#.

I have a windows form with databinded textboxes, comboboxes and a datagrid. Everything works fine until a user enter a wrong value in a textbox binded to a numeric field on the form. There is no way to get back to the old value by pressing escape (canceling changes).

Strangely, this works fine with the datagridview columns: if there is an error in a field, the user can simply hit escape and the cell gets back to its original value.

Is there any way I can do that with common form textboxes?

Thanks,
Justin
Nov 21 '07 #1
2 1831
TonFrere
14 New Member
I hope to help other users by posting a solution to my own problem.

First of all, the problem I had with using the escape key to undo changes was entirely my fault since I mistook two controls of the same name when testing the Undo() method of the textbox control. Anyways, here is how it's done:

On the keydown event, call the undo method if the key is "escape"
if (e.KeyCode == Keys.Escape)
no_Comm_IntText Box.Undo();

I also read a Chapter on Validating data input and Handling Errors in Brian Noyes book "Data Binding with Windows Forms 2.0" -Which I strongly recommend for anyone who would like to avoid a whole lotta work by using databinding.

In this chapter, I learned how to use the ErrorProvider control combine with the "AutoValida te" property and "ValidateChildr en" method of the form. This way, users are not suck in a control if there is an error but they are noticed and they can't save changes until corrections are done.

Justin
Nov 21 '07 #2
Frinavale
9,735 Recognized Expert Moderator Expert
I hope to help other users by posting a solution to my own problem.

First of all, the problem I had with using the escape key to undo changes was entirely my fault since I mistook two controls of the same name when testing the Undo() method of the textbox control. Anyways, here is how it's done:

On the keydown event, call the undo method if the key is "escape"
if (e.KeyCode == Keys.Escape)
no_Comm_IntText Box.Undo();

I also read a Chapter on Validating data input and Handling Errors in Brian Noyes book "Data Binding with Windows Forms 2.0" -Which I strongly recommend for anyone who would like to avoid a whole lotta work by using databinding.

In this chapter, I learned how to use the ErrorProvider control combine with the "AutoValida te" property and "ValidateChildr en" method of the form. This way, users are not suck in a control if there is an error but they are noticed and they can't save changes until corrections are done.

Justin

Thanks for share the solution Justin
Nov 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
10215
by: Etienne Charland | last post by:
Hi, there is an application running on a remote desktop (under Citrix ICA, but the same problem applies for RDC or PC Anywhere). Now, I want to send keys to the remote application from a local app. I tried sending keys in VB with SendKeys, as well as using keybd_event API, but I'm not able to send any keys. It works very well for any local applications, but I can't pass the keys remotely. Is there any way to do it? Thanks! Etienne
9
5917
by: Etienne Charland | last post by:
Hi, there is an application running on a remote desktop (under Citrix ICA, but the same problem applies for RDC or PC Anywhere). Now, I want to send keys to the remote application from a local app. I tried sending keys in VB with SendKeys, as well as using keybd_event API, but I'm not able to send any keys. It works very well for any local applications, but I can't pass the keys remotely. Is there any way to do it? Thanks! Etienne
2
1673
by: John Brock | last post by:
At work we are using a virtual desktop manager called AltDesk (http://www.astonshell.com/), and it is causing a weird and extremely annoying problem with the VB.NET application I am developing. If I start my app, open a test form using ShowDialog() (this is a menu choice on the main app), and then switch to a different virtual desktop, the test form immediately closes (in what seems to be an abnormal way -- the Closing event is raised,...
2
1588
by: John Brock | last post by:
At work we are using a virtual desktop manager called AltDesk (http://www.astonshell.com/), and it is causing a weird and extremely annoying problem with the VB.NET application I am developing. If I start my app, open a test form using ShowDialog() (this is a menu choice on the main app), and then switch to a different virtual desktop, the test form immediately closes (in what seems to be an abnormal way -- the Closing event is raised,...
0
8367
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
8811
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
8703
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
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
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
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
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
1
1914
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.