Hi,
In my C# Windows form MyForm I have some TextBoxes.
In these TextBoxes, we have to detect if the TextChanged event occurs,
if there're changes in these TextBoxes, it will ask if we want to save the
changes when we close the form.
However, when I run the MyForm, it will fetch data from the system and put
into TextBoxes,
and this incurs the textchanged event.
But I am thinking how do I make the TextBox's TextChanged know the
difference between event caused by system and event cuased by user typing?
or are there other events to distinguish this?
Thanks for help.
Jason 4 29802
Hi Jason, In my C# Windows form MyForm I have some TextBoxes. In these TextBoxes, we have to detect if the TextChanged event occurs. However, when I run the MyForm, it will fetch data from the system and put into TextBoxes, and this incurs the textchanged event.
The TextChanged event will be fired no matter if it is the user typing text
into the TextBox, or you changing the Text property in code.
Luckily, there's an easy, though not necessarily very elegant solution to
this. You need to declare a (boolean) variable that you set to true before
you change the TextBox's content in code. Then, in the TextChanged event
handler you would simply check this variable, and if it is true, you will
know that it was you who changed the Text property in code.
Another option would be to monitor the KeyPress/KeyDown/KeyUp events or
disengage the TextChanged event handler before updating the TextBox, but I
see these as too difficult/unnecessary actions since a simple helper
variable will simply do.
--
Regards,
Mr. Jani Järvinen
C# MVP
Helsinki, Finland ja***@removethi s.dystopia.fi http://www.saunalahti.fi/janij/
I think u'd better to declare eventhandler dor TextChanged in ur program
not by desinger..
when u fill data after that write eventhandler dor textbox.
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Hi,
In my C# Windows form MyForm I have some TextBoxes. In these TextBoxes, we have to detect if the TextChanged event occurs, if there're changes in these TextBoxes, it will ask if we want to save the changes when we close the form. However, when I run the MyForm, it will fetch data from the system and put into TextBoxes, and this incurs the textchanged event. But I am thinking how do I make the TextBox's TextChanged know the difference between event caused by system and event cuased by user typing? or are there other events to distinguish this? Thanks for help.
Jason
Another simple solution would be to save all your original strings and not
monitor the text changed event at all. At the end, before finishing your
dialog you just check if your control texts are different from the
originals...
/LM
"Jani Järvinen [MVP]" <ja***@removeth is.dystopia.fi> wrote in message
news:eq******** ******@tk2msftn gp13.phx.gbl... Hi Jason,
In my C# Windows form MyForm I have some TextBoxes. In these TextBoxes, we have to detect if the TextChanged event occurs. However, when I run the MyForm, it will fetch data from the system and put into TextBoxes, and this incurs the textchanged event.
The TextChanged event will be fired no matter if it is the user typing text into the TextBox, or you changing the Text property in code.
Luckily, there's an easy, though not necessarily very elegant solution to this. You need to declare a (boolean) variable that you set to true before you change the TextBox's content in code. Then, in the TextChanged event handler you would simply check this variable, and if it is true, you will know that it was you who changed the Text property in code.
Another option would be to monitor the KeyPress/KeyDown/KeyUp events or disengage the TextChanged event handler before updating the TextBox, but I see these as too difficult/unnecessary actions since a simple helper variable will simply do.
-- Regards,
Mr. Jani Järvinen C# MVP Helsinki, Finland ja***@removethi s.dystopia.fi http://www.saunalahti.fi/janij/
On Sun, 22 Jan 2006 13:20:31 +0800, "Jason Huang"
<Ja************ @hotmail.com> wrote: Hi,
In my C# Windows form MyForm I have some TextBoxes. In these TextBoxes, we have to detect if the TextChanged event occurs, if there're changes in these TextBoxes, it will ask if we want to save the changes when we close the form. However, when I run the MyForm, it will fetch data from the system and put into TextBoxes, and this incurs the textchanged event. But I am thinking how do I make the TextBox's TextChanged know the difference between event caused by system and event cuased by user typing? or are there other events to distinguish this? Thanks for help.
Jason
I presume that you have some boolean flags to indicate when each
TextBox has been changed which are set by the TextChanged event for a
box. Whenever a TextBox is loaded from the system you will need to
explicitly reset the flag for that TextBox to false. Initially you
will need to reset all the flags to false in the startup code for your
form.
rossum
--
The ultimate truth is that there is no ultimate truth This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jbsound |
last post by:
I have been banging my head against this one and I'm sure I'm missing
something:
Got a WinForms app in VB.NET with controls bound to a dataset. For the sake
of this discussion, let's use just one text box control. When the user makes
changes, the first character change in the text box will not set the
underlying DataSet.HasChanges to true. Only the subsequent character change
sets the DataSet.HasChanges to true. Why is that?
More...
|
by: VMI |
last post by:
I'm trying to some dynamic searching to my windows Form so I added code in
my TextBox.TextChanged so that, after every text change, a search is done to
a datatable. So if I want to type the string "Memphis", it'll do a search
(and display) all the items after the user types "M", then another search
(of "Me") when the user types "e", another search of "Mem" after "M", and so
on. The problem is that there's so much data in the table that...
|
by: jorge |
last post by:
Hello
I have the following situation: (everything is dynamic (controls.add))
1. Button.Init {
WasButtonClickFired = true
}
2. TextBox.TextChanged {
WasButtonClickFired?
|
by: Spencer H. Prue |
last post by:
I have a textbox and a button on my asp.net form. I have some Smtp code in my
button click procedure. When the user hits the return for the textbox the
button procedure runs. When the button is clicked the button procedure also
runs. This fine so I get the Smtp code to run either way. The problem is that
the user sometimes hits return AND clicks the "submit" button so the Smtp
code gets executed twice. Should I use Application state and a...
|
by: Fabio Cannizzo |
last post by:
Hi.
The content of my textbox is "ABCD".
If I select the letter 'C' and I press 'X', the content obviously changes to
"ABXD".
Thsi however generates two separate "TextChanged" events
1) "ABCD" ==> "ABD"
2) "ABD" ==> "ABXD"
| |
by: pvdg42 |
last post by:
Working on a web project (academic example) for a beginning VB class where
there are four text boxes, each to hold four characters. I want focus to
shift automatically to the next text box when the user has entered the 4th
character in a given text box.
I'm trying to use the TextChanged event to make this happen, but it appears
as if the TextChanged event never fires? I thought it would fire each time
the user entered a new character so...
|
by: S_K |
last post by:
This is a weird problem..
I have a page with a textbox and a button (along with a bunch of other
stuff). Both the textbox and the button have their SEPERATE events
defined for the textchanged and click events. When I change the text
in the textbox the textchanged event is called as expected. But the
button click event is also called!?
Whats with that?!
|
by: Jason Huang |
last post by:
Hi,
In my C# 1.1 Windows form project, I have a TextBox TextChanged for TextBox1
on the Form1.
How do I limit the TextChanged event to only real user doing something on
that TextBox?
I mean when the Form1 loading, the TextBox1's TextChanged also affected, but
this is not what I want.
Thanks for help.
|
by: David C |
last post by:
I have an asp.net page that contains a FormView with several controls bound
to a SqlDataSource. One of the controls is a TextBox bound to a date
column. I have the following additional properties on the TextBox:
OnTextChanged="txtDestroyed_TextChanged" AutoPostBack="true"
I expected the OnTextChanged event to fire immediately and run the postback
but it does not. The code does not run until I click the "Update" button.
Can anyone...
|
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...
|
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,...
| |
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,...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |