473,626 Members | 3,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to undoing a TextBox

53 New Member
Hi all.
I wanted to change value of a TextBox to previous value of that TextBox when a user types some special data but i couldn't change value in BeforeUpdate or AfterUpdate Event handler!
Is any special command or method exists to undo only one TextBoxe's value of a form?
Thanks in advanced
Jul 1 '10 #1
7 10024
ADezii
8,834 Recognized Expert Expert
@alinagoo
Let's say that you have a 'Bound' Field on a Form named [Margin]. Let's also suppose that if at any time, a User enters a Margin of > 10 into this Field for an existing Record, you then wish to restore the Original Value of that Field. In the AfterUpdate() Event of the [Margin] Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Margin_AfterUpdate()
  2. Dim ctlTBox As TextBox
  3.  
  4. Set ctlTBox = Me![Margin]
  5.  
  6. If ctlTBox > 10 Then
  7.   ctlTBox = ctlTBox.OldValue
  8. End If
  9. End Sub
Jul 1 '10 #2
missinglinq
3,532 Recognized Expert Specialist
What exactly did you try?

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBoxName_AfterUpdate()
  2.  If Me.TextBoxName.Value = "9999" Then
  3.   Me.TextBoxName.Value = Me.TextBoxName.OldValue
  4.  End If
  5. End Sub
should work, replacing 9999 with the triggering value. Omit the quotes, of course, if the value is Numerical instead of Text.

Linq ;0)>
Jul 1 '10 #3
NeoPa
32,567 Recognized Expert Moderator MVP
I don't know what you tried but cancelling an update if the value doesn't fit is pretty straightforward :
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)
  2.     If Me.YourTextBox = "Invalid Value" Then Cancel = True
  3. End Sub
Jul 1 '10 #4
alinagoo
53 New Member
Thanks you all
But NeoPa's method does not worked properly and the method used by Missinglinq and ADezii with OlaValue property works fine.
Good Luck
Jul 1 '10 #5
NeoPa
32,567 Recognized Expert Moderator MVP
NeoPa's method should work if done properly. What did you try (This was asked before)?
Jul 1 '10 #6
alinagoo
53 New Member
@NeoPa
I used "Cancel = True" in BeforeUpdate Event handler of a TextBox to convert value of that TextBox to previous saved value if newly typed value is not in a valid range but it does not work!

Thank
Good Luck
Jul 2 '10 #7
NeoPa
32,567 Recognized Expert Moderator MVP
My mistake. The Cancel = True simply stops the cursor leaving the control. Attempting to set the value in a BeforeUpdate() event procedure always triggers an error, so the trick to doing it properly is to use the .Undo() method.

Using ADezii's situation as an example :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Margin_BeforeUpdate(Cancel As Integer)
  2.     With Me.Margin
  3.         If .Value > 10 Then
  4.             Call .Undo
  5.             Cancel = True
  6.         End If
  7.     End With
  8. End Sub
This leaves the cursor in the control, as well as reverting the data to that before any changes were attempted.
Jul 2 '10 #8

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

Similar topics

0
2115
by: Jonas L | last post by:
Hi, I need to create a textbox which acts as a normal textbox but with the following extra requirements: 1) In-focus color, when the textbox gets focus the backcolor property of the textbox should be set to a, selectable, in-focus color. 2) Out-of-focus color, when the textbox loses focus the backcolor property of the textbox should be set to a, selectable, out-of-focus color.
4
2906
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with some textboxes not updating when i a hit save. for example I have this code in my aspx.cs file: declared:
0
1809
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the first values for each control. Please help me. Thanks for any help. Bye Ozer And here's my code: Imports System Imports System.Data Imports System.Data.OleDb
7
2111
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
2
19849
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
3
2213
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. But while trying to insert a text box to see when a method is used, and putting a counter to bump some variable? The textbox sits there unchanged. I put a breakpoint at the text write
2
3009
by: Mike Fox | last post by:
I am trying to implement undo in an application. The problem is the user wants a granular undo like word or studio. Here's the issue: 1. Bring up a record, and edit a field. 2. move to a new field and edit 3. delete the record 4. Now hit undo. If I "undo" the delete using datarow.undo() or datarow.rejectchanges(), it reverts to the original state and I lose the changes fromstep 1 and 2. The user wants to be able to undo JUST the...
0
2395
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
8
36878
by: Marco Pais | last post by:
Hi there. How can I change the background color of a textbox when it gets the focus? I can handle the "Enter" event and do this private void txtDummie_Enter(object sender, EventArgs e) { txtDummie.BackColor=Color.Red; }
0
836
by: jatin vijay nahar | last post by:
how to undoing in richtextbox in c#.net
0
8265
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
8705
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
8637
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
8504
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...
0
4092
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...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
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
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.