473,837 Members | 1,436 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 1836
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
10230
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
5942
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
1684
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
1599
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
9839
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
9682
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
10564
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...
1
10621
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7806
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
6998
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
5668
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
4474
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
4039
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.