Click here to Skip to main content
15,887,967 members
Home / Discussions / C#
   

C#

 
GeneralTextBox calculations on the fly. Pin
FredSP2-May-04 4:36
FredSP2-May-04 4:36 
GeneralRe: TextBox calculations on the fly. Pin
Dave Kreskowiak2-May-04 4:40
mveDave Kreskowiak2-May-04 4:40 
GeneralRe: TextBox calculations on the fly. Pin
FredSP2-May-04 16:49
FredSP2-May-04 16:49 
GeneralRe: TextBox calculations on the fly. Pin
Heath Stewart2-May-04 6:42
protectorHeath Stewart2-May-04 6:42 
GeneralRe: TextBox calculations on the fly. Pin
FredSP2-May-04 16:45
FredSP2-May-04 16:45 
GeneralRe: TextBox calculations on the fly. Pin
..Hubert..3-May-04 1:17
..Hubert..3-May-04 1:17 
GeneralRe: TextBox calculations on the fly. Pin
Heath Stewart3-May-04 1:52
protectorHeath Stewart3-May-04 1:52 
GeneralRe: TextBox calculations on the fly. Pin
..Hubert..4-May-04 7:51
..Hubert..4-May-04 7:51 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasstextchangedtopic.asp
and cite: This event is raised if the Text property is changed by either a programmatic modification or user interaction.

Heath Stewart wrote:
so then my original reply is correct: the TextChanged event is only fired when the control looses focus

I've even coded a little toy to play with textbox events, and on my system (WinXP Pro, .Net 1.1) the TextChangedEvent is fired everytime user changes the text, not when control loses focus.

using System;<br />
using System.Windows.Forms;<br />
using System.ComponentModel;<br />
<br />
namespace WindowsApplication47<br />
{<br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.TextBox tb;<br />
		private System.Windows.Forms.ListBox lb;<br />
		<br />
		public Form1()<br />
		{<br />
			this.Text="TextBox events:";<br />
			lb=new ListBox();<br />
			lb.Dock=DockStyle.Fill;<br />
			this.Controls.Add(lb);<br />
			tb=new TextBox();<br />
			tb.Dock=DockStyle.Top;<br />
			this.Controls.Add(tb);<br />
			tb.TextChanged+=new EventHandler(tb_TextChanged);<br />
			tb.LostFocus+=new EventHandler(tb_LostFocus);<br />
			tb.Validating+=new CancelEventHandler(tb_Validating);<br />
		}<br />
		private void tb_TextChanged(object sender, EventArgs e)<br />
		{<br />
			this.AddToList("TextChanged. Current text is:"+this.tb.Text);<br />
		}<br />
		private void tb_LostFocus(object sender, EventArgs e)<br />
		{<br />
			this.AddToList("LostFocus.");<br />
		}<br />
		private void tb_Validating(object sender, CancelEventArgs e)<br />
		{<br />
			this.AddToList("Validating.");<br />
		}<br />
		void AddToList(object val)<br />
		{<br />
			this.lb.Items.Add(val); <br />
			this.lb.SelectedIndex=this.lb.Items.Count-1;<br />
		}<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
	}<br />
}


Could you play with this toy a while and tell me where are lost focus and other events you are talking about?
btw:
This may be true if we are talking about databinding. The difference is that the control itself does not ends "editing" of the current datasource (ie. row). So then the magic formula:
this.textBox.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();<br />
in TextChanged event routine makes data immediately changed in datasource.
Smile | :)
GeneralRe: TextBox calculations on the fly. Pin
Heath Stewart4-May-04 8:04
protectorHeath Stewart4-May-04 8:04 
GeneralArray and form Pin
brugi821-May-04 23:20
brugi821-May-04 23:20 
GeneralRe: Array and form Pin
leppie2-May-04 0:54
leppie2-May-04 0:54 
GeneralRe: Array and form Pin
Dave Kreskowiak2-May-04 4:36
mveDave Kreskowiak2-May-04 4:36 
GeneralRe: Array and form Pin
thomasa2-May-04 22:23
thomasa2-May-04 22:23 
GeneralRe: Array and form Pin
brugi823-May-04 1:10
brugi823-May-04 1:10 
GeneralHiding Toolbar Pin
Mazdak1-May-04 21:10
Mazdak1-May-04 21:10 
GeneralRe: Hiding Toolbar Pin
Stefan Troschuetz1-May-04 21:46
Stefan Troschuetz1-May-04 21:46 
GeneralRe: Hiding Toolbar Pin
Mazdak1-May-04 22:09
Mazdak1-May-04 22:09 
GeneralRe: Hiding Toolbar Pin
Heath Stewart2-May-04 6:39
protectorHeath Stewart2-May-04 6:39 
GeneralRe: Hiding Toolbar Pin
Mazdak2-May-04 8:31
Mazdak2-May-04 8:31 
GeneralRe: Hiding Toolbar Pin
Heath Stewart2-May-04 8:51
protectorHeath Stewart2-May-04 8:51 
GeneralRe: Hiding Toolbar Pin
Mazdak2-May-04 8:56
Mazdak2-May-04 8:56 
GeneralRe: Hiding Toolbar Pin
Heath Stewart2-May-04 8:59
protectorHeath Stewart2-May-04 8:59 
GeneralRe: Hiding Toolbar Pin
Mazdak2-May-04 9:47
Mazdak2-May-04 9:47 
GeneralRe: Hiding Toolbar Pin
Mazdak2-May-04 9:57
Mazdak2-May-04 9:57 
GeneralRe: Hiding Toolbar Pin
Heath Stewart2-May-04 10:18
protectorHeath Stewart2-May-04 10:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.